public function testMap() { $env = ['user' => 'ikr']; $io = IO::of($env)->map(F\curry('F\\prop', 'user'))->map(F\curry('F\\map', 'strtoupper')); $env['user'] = '******'; $this->assertEquals(Maybe::of('ROOT'), $io->unsafePerformIO()); }
public function testCurriedBuiltInArrayMap() { $double = function ($x) { return $x * 2; }; $doubleAll = F\curry('array_map', $double); $this->assertSame([2, 4, 6], $doubleAll([1, 2, 3])); }
public function testHasPrecurriedVersion() { $join = function ($a, $b) { return "{$a} {$b}"; }; $data = ['name' => ['first' => 'James', 'last' => 'Bond'], 'code' => '007', 'country' => 'UK']; $this->assertSame('James Bond 007', call_user_func(call_user_func(F\C1\converge($join), [F\compose(F\curry('implode', ' '), 'array_values', F\C2\propOr('', 'name')), F\C2\propOr('', 'code')]), $data)); }
function minBy($fn) { return \F\curry('F\\minBy', $fn); }
<?php /** * Created by PhpStorm. * User: azder * Date: 10/08/2015 * Time: 5:04 */ error_reporting(E_ALL); require_once '../src/fun.php'; use function F\val; $values = [1, 0, -1, 'yes', 'no', 'on', 'off', '0.0']; $object = new stdClass(); $object->test = $values; $object->test2 = 'test2'; array_map(function ($value) { echo '' . $value . ' -> ' . var_export(F\tril($value), true) . PHP_EOL; }, $values); echo '-------------------' . PHP_EOL; array_map(function ($value) { echo '' . $value . ' -> ' . var_export(F\ident($value), true) . PHP_EOL; }, $values); echo '-------------------' . PHP_EOL; echo F\val(4, $values) . PHP_EOL; echo var_export(F\val('test', $object), true) . PHP_EOL; $test2 = F\curry('F\\val', 'test2'); echo var_export($test2($object), true) . PHP_EOL; echo '-------------------' . PHP_EOL; var_export(val('test', $object)); var_export(val('', $object)); var_export(val(null, $object));