How to use the pfun.either.Right function in pfun

To help you get started, we’ve selected a few pfun examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github suned / pfun / tests / test_either.py View on Github external
def test_identity_law(self, value):
        assert Left(value).map(identity) == Left(value)
        assert Right(value).map(identity) == Right(value)
github suned / pfun / tests / test_either.py View on Github external
def test_map_m(self):
        assert map_m(Right, range(3)) == Right((0, 1, 2))
github suned / pfun / tests / test_either.py View on Github external
def test_composition_law(self, f: Unary, g: Unary, value):
        h = compose(f, g)
        assert Left(value).map(h) == Left(value).map(g).map(f)
        assert Right(value).map(h) == Right(value).map(g).map(f)
github suned / pfun / tests / test_either.py View on Github external
def test_filter_m(self):
        assert filter_m(lambda v: Right(v % 2 == 0), range(3)) == Right((0, 2))
github suned / pfun / tests / test_effect.py View on Github external
def test_absolve(self):
        right = either.Right(1)
        left = either.Left('error')
        right_effect = effect.success(right)
        left_effect = effect.success(left)
        assert effect.absolve(right_effect).run(None) == 1
        with pytest.raises(Exception):
            # todo
            effect.absolve(left_effect).run(None)
github suned / pfun / pfun / either.py View on Github external
Test if ``other`` is a `Right` wrapping the same value as
        this instance

        Example:
            >>> Right('value') == Right('value')
            True
            >>> Right('another value') == Right('value')
            False

        Args:
            other: object to compare with
        Return:
            True if other is a `Right` instance and wraps the same \
            value as this instance, False otherwise
        """
        return isinstance(other, Right) and self.get == other.get
github suned / pfun / pfun / either.py View on Github external
def sequence(iterable: Iterable[Either[A, B]]) -> Either[Iterable[A], B]:
    """
    Evaluate each ``Either`` in `iterable` from left to right
    and collect the results

    Example:
        >>> sequence([Right(v) for v in range(3)])
        Right((0, 1, 2))

    Args:
        iterable: The iterable to collect results from
    Return:
        ``Either`` of collected results
    """
    return cast(Either[Iterable[A], B], sequence_(Right, iterable))
github suned / pfun / pfun / either.py View on Github external
def map(self, f: Callable[[A], C]) -> Either[Any, C]:
        return Right(f(self.get))
github suned / pfun / pfun / http.py View on Github external
                lambda: Right(aiohttp.ClientSession(
                    connector=connector,
                    cookies=cookies,
                    headers=headers,
                    skip_auto_headers=skip_auto_headers,
                    auth=auth,
                    json_serialize=json_serialize,
                    version=version,
                    cookie_jar=cookie_jar,
                    read_timeout=read_timeout,
                    conn_timeout=conn_timeout,
                    timeout=timeout,
                    raise_for_status=raise_for_status,
                    connector_owner=connector_owner,
                    auto_decompress=auto_decompress,
                    requote_redirect_url=requote_redirect_url,
                    trust_env=trust_env,