API Reference

Either

Either - Contains the Either[TA, TB] type and related functions. It was strongly inspired by the Haskell Data.Either module.

More information on the Haskell Data.Either type can be found here: https://hackage.haskell.org/package/base/docs/Data-Either.html

class pyella.either.Either

Represents values with two possibilities: a value of type Either[TA, TB] is either Left[TA] or Right[TB].

bind(apply: Callable[[TB_co], Either[TA_co, TC_co]]) Either[TA_co, TC_co]

Alias for bind(self, apply)

chain(em1: Either[TA_co, TC_co]) Either[TA_co, TC_co]

Alias for chain(self, em1)

discard(apply: Callable[[TB_co], Either[TA_co, TB_co]]) Either[TA_co, TB_co]

Alias for discard(self, apply)

either(map_left_: Callable[[TA_co], TC_co], map_right_: Callable[[TB_co], TC_co]) TC_co

Alias for either(map_left, map_right, self)

fmap(apply: Callable[[TB_co], TC_co]) Either[TA_co, TC_co]

Alias for fmap(self, apply)

if_left(fallback: TB_co) TB_co

Alias for if_left(self, fallback)

if_right(fallback: TA_co) TA_co

Alias for if_right(self, fallback)

is_left() bool

Alias for is_left(self)

is_right() bool

Alias for is_right(self)

map_left(apply: Callable[[TA_co], TC_co]) Either[TC_co, TB_co]

Alias for map_left(self, apply)

static pure(value: TB_co) Either[TA_co, TB_co]

Alias for pure(self)

replace(value: TC_co) Either[TA_co, TC_co]

Alias for replace(self, value)

to_maybe() Maybe[TB_co]

Alias for to_maybe(self)

to_optional() TB_co | None

Alias for to_optional(self)

class pyella.either.Left(value: TA_co)

Represents the left side of an Either[TA, TB], often used to represent the failure case

class pyella.either.Right(value: TB_co)

Represents the right side of an Either[TA, TB], often used to represent the success case

pyella.either.bind(em0: Either[TC_co, TA_co], apply: Callable[[TA_co], Either[TC_co, TB_co]]) Either[TC_co, TB_co]

Map the value of a Right[TA] to a new Either[TC, TB]

Raises:

ArgumentTypeError – If the result of the apply function is not a Either

Returns:

A new Right[TB] or Left[TC]

Note

Haskell: >>=

pyella.either.chain(em0: Either[TC_co, TA_co], em1: Either[TC_co, TB_co]) Either[TC_co, TB_co]

Discard the current value of a Right[TA] and replace it with the given Either[TC, TB]

Note

Haskell: >>

pyella.either.discard(em0: Either[TC_co, TA_co], apply: Callable[[TA_co], Either[TC_co, TB_co]]) Either[TC_co, TA_co]

Apply the given function to the value of a Right[TA] and discard the result

pyella.either.either(map_left_: Callable[[TA_co], TC_co], map_right_: Callable[[TB_co], TC_co], em0: Either[TA_co, TB_co]) TC_co

Map the value of the given Either with map_right_ if its Right or with map_left_ when it’s Left.

Note

Haskell: either

pyella.either.fmap(em0: Either[TC_co, TA_co], apply: Callable[[TA_co], TB_co]) Either[TC_co, TB_co]

Map a function over the value of an Either when it’s Right[TA], otherwise return itself

Note

Haskell: fmap

pyella.either.if_left(em0: Either[TA_co, TB_co], fallback: TB_co) TB_co

Return the contents of a Right[TB] or a fallback value if it’s Left

Note

Haskell: fromRight

pyella.either.if_right(em0: Either[TA_co, TB_co], fallback: TA_co) TA_co

Return the contents of a Left or a fallback value if it’s Right

Note

Haskell: fromLeft

pyella.either.is_left(em0: Either[TA_co, TB_co]) bool

Is the given Either a Left?

Note

Haskell: isLeft

pyella.either.is_right(em0: Either[TA_co, TB_co]) bool

Is the given Either a Right?

Note

Haskell: isRight

pyella.either.left(value: TA_co) Left[TA_co, TB_co]

Create a Left[TA] with the given value

pyella.either.lefts(eithers: Iterable[Either[TA_co, TB_co]]) List[TA_co]

Return a list of all the Left values in the given list of Eithers

Note

Haskell: lefts

pyella.either.map_left(em0: Either[TA_co, TB_co], apply: Callable[[TA_co], TC_co]) Either[TC_co, TB_co]

Map a function over the value of an Either when it’s Left, otherwise return itself

Note

Haskell: first

pyella.either.pure(value: TB_co) Right[TA_co, TB_co]

Create a Right[TB] from a value

Note

Haskell: pure

pyella.either.replace(self, value: TC_co) Either[TA_co, TC_co]

Replace the value of an Either with a new value

Returns:

itself if the Either is Left, otherwise a Right[TC] with provided value

Note

Haskell: <$

pyella.either.right(value: TB_co) Right[TA_co, TB_co]

Alias for pure(value)

pyella.either.rights(eithers: Iterable[Either[TA_co, TB_co]]) List[TB_co]

Return a list of all the Right values in the given list of Eithers

Note

Haskell: rights

pyella.either.to_maybe(em0: Either[TA_co, TB_co]) Maybe[TB_co]

Convert an Either[TA, TB] to a Maybe[TB] by mapping Left to Nothing and Right to Just[TB]

Note

Haskell: toMaybe

pyella.either.to_optional(em0: Either[TA_co, TB_co]) TB_co | None

Convert an Either[TA, TB] to an Optional[TB] by mapping Left[TA] to None and Right[TB] to its value

Returns:

None if the Either is Left, otherwise its value

Maybe

Maybe - Contains the Maybe type and related functions. Its implementation was strongly inspired by the Haskell Data.Maybe type.

More information on the Haskell Data.Maybe type can be found here: https://hackage.haskell.org/package/base/docs/Data-Maybe.html

class pyella.maybe.Just(value: TA_co)

An instance of type Just[A] contains a value of type A.

class pyella.maybe.Maybe

Provides a way to handle values that may or may not be present: A value of type Maybe[A] is either Nothing or Just[A].

bind(apply: Callable[[TA_co], Maybe[TB_co]]) Maybe[TB_co]

Alias for bind(self, apply)

chain(em1: Maybe[TB_co]) Maybe[TB_co]

Alias for chain(self, em1)

discard(apply: Callable[[TA_co], Maybe[TB_co]]) Maybe[TA_co]

Alias for discard(self, apply)

fmap(apply: Callable[[TA_co], TB_co]) Maybe[TB_co]

Alias for fmap(self, apply)

from_maybe(fallback: TA_co) TA_co

Alias for from_maybe(fallback, self)

is_nothing() bool

Alias for is_nothing(self)

maybe(fallback: TB_co, apply: Callable[[TA_co], TB_co]) TB_co

Alias for maybe(fallback, apply, self)

static of(value: TA_co)

Alias for of(value)

static pure(value: TA_co)

Alias for pure(value)

replace(value: TB_co) Maybe[TB_co]

Alias for replace(self, value)

to_optional() TA_co | None

Alias for to_optional(self)

class pyella.maybe.Nothing

An instance of type Nothing contains no value.

pyella.maybe.bind(em0: Maybe[TA_co], apply: Callable[[TA_co], Maybe[TB_co]]) Maybe[TB_co]

Map the value of a Just[TA] to a new Maybe[TB]

Raises:

ArgumentTypeError – If the result of the apply function is not a Maybe

Note

Haskell: >>=

pyella.maybe.chain(em0: Maybe[TA_co], em1: Maybe[TB_co]) Maybe[TB_co]

Discard the current value of a Just[TA] and replace it with the given Maybe[TA]

Note

Haskell: >>

pyella.maybe.discard(em0: Maybe[TA_co], apply: Callable[[TA_co], Maybe[TB_co]]) Maybe[TA_co]

Apply the given function to the value of a Just[TA] and discard the result

pyella.maybe.fmap(em0: Maybe[TA_co], apply: Callable[[TA_co], TB_co]) Maybe[TB_co]

Map a function over the value of a Maybe[TA] when it’s Just[TA], otherwise return Nothing

Note

Haskell: fmap

pyella.maybe.from_maybe(fallback: TA_co, em0: Maybe[TA_co]) TA_co

Return the value of a Maybe when it’s Just, otherwise return a fallback value

Note

Haskell: fromMaybe

pyella.maybe.is_nothing(em0: Maybe[TA_co]) bool

Is the given Maybe Nothing?

Note

Haskell: isNothing

pyella.maybe.maybe(fallback: TB_co, apply: Callable[[TA_co], TB_co], em0: Maybe[TA_co]) TB_co

Map and return the value of the given Maybe[TA] when it’s Just[TA], otherwise return a fallback value

Returns:

Mapped Just value or fallback when Nothing

Note

Haskell: pure

pyella.maybe.of(value: TA_co) Maybe[TA_co]

Alias for pure(value)

pyella.maybe.pure(value: TA_co)

Create a Maybe[TA] from a value

Returns:

Nothing if the value is None, otherwise Just(value)

Note

Haskell: pure

pyella.maybe.replace(em0: Maybe[TA_co], value: TB_co) Maybe[TB_co]

Replace the value of a Maybe with a new value.

Returns:

Nothing if the Maybe is Nothing, otherwise a Just with provided value

Note

Haskell: <$

pyella.maybe.to_optional(em0: Maybe[TA_co]) TA_co | None

Convert a Maybe[TA] to an Optional[TA]

Returns:

None if the Maybe is Nothing, otherwise its value