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 eitherLeft[TA]
orRight[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 newEither[TC, TB]
- Raises:
ArgumentTypeError – If the result of the apply function is not a
Either
- Returns:
A new
Right[TB]
orLeft[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 givenEither[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 itsRight
or with map_left_ when it’sLeft
.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’sRight[TA]
, otherwise return itselfNote
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’sLeft
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’sRight
Note
Haskell: fromLeft
- 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 ofEithers
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’sLeft
, otherwise return itselfNote
Haskell: first
- pyella.either.pure(value: TB_co) Right[TA_co, TB_co]
Create a
Right[TB]
from a valueNote
Haskell: pure
- pyella.either.replace(self, value: TC_co) Either[TA_co, TC_co]
Replace the value of an
Either
with a new valueNote
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 ofEithers
Note
Haskell: rights
- pyella.either.to_maybe(em0: Either[TA_co, TB_co]) Maybe[TB_co]
Convert an
Either[TA, TB]
to aMaybe[TB]
by mappingLeft
toNothing
andRight
toJust[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 mappingLeft[TA]
toNone
andRight[TB]
to 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 typeA
.
- class pyella.maybe.Maybe
Provides a way to handle values that may or may not be present: A value of type
Maybe[A]
is eitherNothing
orJust[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 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 newMaybe[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 givenMaybe[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’sJust[TA]
, otherwise returnNothing
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’sJust[TA]
, otherwise return a fallback valueNote
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 isNone
, otherwiseJust(value)
Note
Haskell: pure