Ardent\Option::fromPredicate PHP Method

fromPredicate() public static method

public static fromPredicate ( callable $f, $value )
$f callable
    public static function fromPredicate(callable $f, $value)
    {
        return $f($value) ? Option::some($value) : Option::none();
    }

Usage Example

コード例 #1
0
ファイル: OptionTest.php プロジェクト: morrisonlevi/ardent
 public function testFromPredicate_WithUnmatched_ReturnsNone()
 {
     $expect = 13;
     $f = function ($input) {
         return false;
     };
     $ifSome = function ($input) {
         $this->fail();
     };
     $ifNone = function () use($expect) {
         return $expect;
     };
     $actual = Option::fromPredicate($f, $expect)->match($ifSome, $ifNone);
     $this->assertEquals($expect, $actual);
 }