コード例 #1
0
def test_option_some_bind_piped():
    binder: Callable[[int], Option[int]] = lambda x: Some(x + 1)
    xs = Some(42)
    ys = xs.pipe(option.bind(binder), )

    for value in ys.match(Some):
        assert value == 43
        break
    else:
        assert False
コード例 #2
0
ファイル: test_option.py プロジェクト: exyi/Expression
def test_option_some_bind_piped():
    xs = Some(42)
    ys = xs.pipe(option.bind(lambda x: Some(x + 1)), )

    assert ys.match(
        Some,
        lambda some: some.value == 43,
        _,
        False,
    )
コード例 #3
0
 def bind(self, xs: Option[TSource], fn: Callable[[TSource],
                                                  Option[TResult]]):
     return option.bind(fn)(xs)
コード例 #4
0
 def combine(self, xs: Option[TSource],
             ys: Option[TSource]) -> Option[TSource]:
     binder: Callable[[Any], Option[TSource]] = lambda _: ys
     return option.bind(binder)(xs)