コード例 #1
0
def test_option_none_map_piped():
    xs: Option[int] = Nothing
    mapper: Callable[[int], int] = lambda x: x + 1
    map = option.map(mapper)
    ys = xs.pipe(map)

    assert ys is Nothing
コード例 #2
0
ファイル: test_option.py プロジェクト: exyi/Expression
def test_option_some_map_piped():
    xs = Some(42)
    ys: Option[int] = xs.pipe(option.map(lambda x: x + 1))

    for y in ys:
        assert y == 43
        break
    else:
        assert False
コード例 #3
0
def test_option_some_map_piped():
    xs = Some(42)
    mapper: Callable[[int], int] = lambda x: x + 1
    ys: Option[int] = xs.pipe(option.map(mapper))

    for y in ys.match(Some):
        assert y == 43
        break
    else:
        assert False
コード例 #4
0
ファイル: fetch.py プロジェクト: exyi/Expression
async def fetch(
    next: HttpFunc[Option[ClientResponse], TResult, TError],
    ctx: HttpContext,
) -> Result[Context[TResult], TError]:
    session = ctx.Request.SessionFactory()
    builder: Callable[[Any], HttpContent] = lambda builder: builder()

    result: HttpFuncResult
    try:
        content: Option[Any] = pipe(ctx.Request.ContentBuilder,
                                    option.map(builder))
        json = pipe(content, option.default_value(None))
        method = ctx.Request.Method.value
        url = ctx.Request.UrlBuilder(ctx)

        print(f"Fetching: {url}")
        async with session.request(method=method, url=url, json=json) as resp:
            result = await next(ctx.replace(Response=Some(resp)))
    except Exception as ex:
        print(f"fetch: {ex}")
        result = Error(ex)

    return result
コード例 #5
0
ファイル: test_option.py プロジェクト: exyi/Expression
def test_option_none_map_piped():
    xs: Option[int] = Nothing
    map = option.map(lambda x: x + 1)
    ys = xs.pipe(map)
    assert ys.match(Some, lambda some: False, _, True)