new Future()
((α → Void), (β → Void) → Void) → Future[α, β] Future[α, β] <: Chain[β] , Monad[β] , Functor[β] , Show
The Future[α, β]
structure represents values that depend on time. This
allows one to model time-based effects explicitly, such that one can have
full knowledge of when they're dealing with delayed computations, latency,
or anything that can not be computed immediately.
A common use for this structure is to replace the usual Continuation-Passing Style form of programming, in order to be able to compose and sequence time-dependent effects using the generic and powerful monadic operations.
Methods
-
bimap()
@Future[α, β] => (α → γ), (β → δ) → Future[γ, δ]
-
Maps both sides of the disjunction.
-
chain()
@Future[α, β] => (β → Future[α, γ]) → Future[α, γ]
-
Transforms the succesful value of the
Future[α, β]
using a function to a monad. -
fold()
@Future[α, β] => (α → γ), (β → γ) → Future[δ, γ]
-
Catamorphism. Takes two functions, applies the leftmost one to the failure value, and the rightmost one to the successful value, depending on which one is present.
-
map()
@Future[α, β] => (β → γ) → Future[α, γ]
-
Transforms the successful value of the
Future[α, β]
using a regular unary function. -
memoise()
((α → Void), (β → Void) → Void) → Future[α, β]
-
Creates a
Future[α, β]
that computes the action at most once.Since this function will remember the resolved value of the future, it's expected to be used only for pure actions, otherwise you may not be able to observe the effects.
-
of()
β → Future[α, β]
-
Constructs a new
Future[α, β]
containing the single valueβ
.β
can be any value, includingnull
,undefined
, or anotherFuture[α, β]
structure. -
orElse()
@Future[α, β] => (α → Future[γ, β]) → Future[γ, β]
-
Transforms a failure value into a new
Future[α, β]
. Does nothing if the structure already contains a successful value. -
rejectedMap()
@Future[α, β] => (α → γ) → Future[γ, β]
-
Maps the left side of the disjunction (failure).
-
swap()
@Future[α, β] => Void → Future[β, α]
-
Swaps the disjunction values.
-
toString()
@Future[α, β] => Void → String
-
Returns a textual representation of the
Future[α, β]