Modifier and Type | Method and Description |
---|---|
IO<A> |
catchError(Fn1<? super Throwable,? extends Monad<A,IO<?>>> recoveryFn)
|
<B> IO<B> |
discardL(Applicative<B,IO<?>> appB)
Sequence both this
Applicative and appB , discarding this Applicative's
result and returning appB . |
<B> IO<A> |
discardR(Applicative<B,IO<?>> appB)
Sequence both this
Applicative and appB , discarding appB's result and
returning this Applicative . |
IO<A> |
ensuring(IO<?> ensureIO)
|
IO<A> |
exceptionally(Fn1<? super Throwable,? extends A> recoveryFn)
Deprecated.
in favor of canonical
catchError(Fn1) |
static <A> IO<A> |
externallyManaged(Fn0<CompletableFuture<A>> supplier)
Static factory method for creating an
IO from an externally managed source of
completable futures . |
<B> IO<B> |
flatMap(Fn1<? super A,? extends Monad<B,IO<?>>> f)
Chain dependent computations that may continue or short-circuit based on previous results.
|
<B> IO<B> |
fmap(Fn1<? super A,? extends B> fn)
Covariantly transmute this functor's parameter using the given mapping function.
|
static <A> IO<A> |
fuse(IO<A> io)
Fuse all fork opportunities of a given
IO such that, unless it is pinned
(or is originally externally managed ), no parallelism will be used when
running it, regardless of what semantics are used when it is executed. |
static <A> IO<A> |
interruptible(IO<A> io)
|
static <A> IO<A> |
io(A a)
Static factory method for creating an
IO that just returns a when performed. |
static <A> IO<A> |
io(Fn0<? extends A> fn0)
Static factory method for coercing a lambda to an
IO . |
static IO<Unit> |
io(SideEffect sideEffect)
|
<B> Lazy<IO<B>> |
lazyZip(Lazy<? extends Applicative<Fn1<? super A,? extends B>,IO<?>>> lazyAppFn)
Given a
lazy instance of this applicative over a mapping function, "zip" the two instances together
using whatever application semantics the current applicative supports. |
static <A> IO<A> |
memoize(IO<A> io)
|
static <A> IO<A> |
monitorSync(Object lock,
IO<A> io)
Synchronize the given
IO using the provided lock object. |
static <A> IO<A> |
pin(IO<A> io,
Executor executor)
|
<B> IO<B> |
pure(B b)
Lift the value
b into this applicative functor. |
static Pure<IO<?>> |
pureIO()
|
IO<Either<Throwable,A>> |
safe()
|
IO<A> |
throwError(Throwable throwable)
Throw an error value of type
E into the monad . |
static <A> IO<A> |
throwing(Throwable t)
|
<B> IO<B> |
trampolineM(Fn1<? super A,? extends MonadRec<RecursiveResult<A,B>,IO<?>>> fn)
Given some operation yielding a
RecursiveResult inside this MonadRec , internally trampoline the
operation until it yields a termination instruction. |
CompletableFuture<A> |
unsafePerformAsyncIO()
Returns a
CompletableFuture representing the result of this eventual effect. |
abstract CompletableFuture<A> |
unsafePerformAsyncIO(Executor executor)
Returns a
CompletableFuture representing the result of this eventual effect. |
abstract A |
unsafePerformIO()
Run the effect represented by this
IO instance, blocking the current thread until the effect terminates. |
<B> IO<B> |
zip(Applicative<Fn1<? super A,? extends B>,IO<?>> appFn)
Given another instance of this applicative over a mapping function, "zip" the two instances together using
whatever application semantics the current applicative supports.
|
public abstract A unsafePerformIO()
IO
instance, blocking the current thread until the effect terminates.public final CompletableFuture<A> unsafePerformAsyncIO()
CompletableFuture
representing the result of this eventual effect. By default, this will
immediately run the effect in terms of the implicit Executor
available to CompletableFuture
(usually the ForkJoinPool
). Note that specific IO
constructions may allow
this method to delegate to externally-managed CompletableFuture
instead of synthesizing their own.CompletableFuture
representing this IO
's eventual resultunsafePerformAsyncIO(Executor)
public abstract CompletableFuture<A> unsafePerformAsyncIO(Executor executor)
CompletableFuture
representing the result of this eventual effect. By default, this will
immediately run the effect in terms of the provided Executor
. Note that specific IO
constructions may allow this method to delegate to externally-managed CompletableFuture
instead of
synthesizing their own.executor
- the Executor
to run the CompletableFuture
fromCompletableFuture
representing this IO
's eventual resultunsafePerformAsyncIO()
@Deprecated public final IO<A> exceptionally(Fn1<? super Throwable,? extends A> recoveryFn)
catchError(Fn1)
Throwable
to the result type A
, if this IO
successfully
yields a result, return it; otherwise, map the Throwable
to the result type and return that.recoveryFn
- the recovery functionIO
public final IO<Either<Throwable,A>> safe()
IO
that will never throw by lifting the result of this IO
into Either
,
catching any Throwable
and wrapping it in a left
.IO
public final <B> IO<B> pure(B b)
b
into this applicative functor.pure
in interface Applicative<A,IO<?>>
pure
in interface Monad<A,IO<?>>
pure
in interface MonadError<Throwable,A,IO<?>>
pure
in interface MonadRec<A,IO<?>>
B
- the type of the returned applicative's parameterb
- the valuepublic final <B> IO<B> fmap(Fn1<? super A,? extends B> fn)
fmap
in interface Applicative<A,IO<?>>
fmap
in interface Functor<A,IO<?>>
fmap
in interface Monad<A,IO<?>>
fmap
in interface MonadError<Throwable,A,IO<?>>
fmap
in interface MonadRec<A,IO<?>>
B
- the new parameter typefn
- the mapping functionpublic final <B> IO<B> zip(Applicative<Fn1<? super A,? extends B>,IO<?>> appFn)
zip
in interface Applicative<A,IO<?>>
zip
in interface Monad<A,IO<?>>
zip
in interface MonadError<Throwable,A,IO<?>>
zip
in interface MonadRec<A,IO<?>>
B
- the resulting applicative parameter typeappFn
- the other applicative instancepublic final <B> Lazy<IO<B>> lazyZip(Lazy<? extends Applicative<Fn1<? super A,? extends B>,IO<?>>> lazyAppFn)
lazy
instance of this applicative over a mapping function, "zip" the two instances together
using whatever application semantics the current applicative supports. This is useful for applicatives that
support lazy evaluation and early termination.lazyZip
in interface Applicative<A,IO<?>>
lazyZip
in interface Monad<A,IO<?>>
lazyZip
in interface MonadError<Throwable,A,IO<?>>
lazyZip
in interface MonadRec<A,IO<?>>
B
- the resulting applicative parameter typelazyAppFn
- the lazy other applicative instanceMaybe
,
Either
public final <B> IO<B> discardL(Applicative<B,IO<?>> appB)
Applicative
and appB
, discarding this Applicative's
result and returning appB
. This is generally useful for sequentially performing side-effects.discardL
in interface Applicative<A,IO<?>>
discardL
in interface Monad<A,IO<?>>
discardL
in interface MonadError<Throwable,A,IO<?>>
discardL
in interface MonadRec<A,IO<?>>
B
- the type of the returned Applicative's parameterappB
- the other Applicativepublic final <B> IO<A> discardR(Applicative<B,IO<?>> appB)
Applicative
and appB
, discarding appB's
result and
returning this Applicative
. This is generally useful for sequentially performing side-effects.discardR
in interface Applicative<A,IO<?>>
discardR
in interface Monad<A,IO<?>>
discardR
in interface MonadError<Throwable,A,IO<?>>
discardR
in interface MonadRec<A,IO<?>>
B
- the type of appB's parameterappB
- the other Applicativepublic final <B> IO<B> flatMap(Fn1<? super A,? extends Monad<B,IO<?>>> f)
flatMap
in interface Monad<A,IO<?>>
flatMap
in interface MonadError<Throwable,A,IO<?>>
flatMap
in interface MonadRec<A,IO<?>>
B
- the resulting monad parameter typef
- the dependent computation over Apublic <B> IO<B> trampolineM(Fn1<? super A,? extends MonadRec<RecursiveResult<A,B>,IO<?>>> fn)
RecursiveResult
inside this MonadRec
, internally trampoline the
operation until it yields a termination
instruction.
Stack-safety depends on implementations guaranteeing that the growth of the call stack is a constant factor independent of the number of invocations of the operation. For various examples of how this can be achieved in stereotypical circumstances, see the referenced types.
trampolineM
in interface MonadRec<A,IO<?>>
B
- the ultimate resulting carrier typefn
- the function to internally trampolineMonadRec
for a basic implementation
,
for a {@link CoProduct2 coproduct} implementation
,
for an implementation leveraging an already stack-safe {@link Monad#flatMap(Fn1)}
,
for a {@link MonadT monad transformer} implementation
public final IO<A> throwError(Throwable throwable)
E
into the monad
.throwError
in interface MonadError<Throwable,A,IO<?>>
throwable
- the error typemonad
public final IO<A> catchError(Fn1<? super Throwable,? extends Monad<A,IO<?>>> recoveryFn)
catchError
in interface MonadError<Throwable,A,IO<?>>
recoveryFn
- the catch functionMonad
public static <A> IO<A> interruptible(IO<A> io)
IO
in an IO
that first checks if the thread
the
IO
runs on is interrupted
. If it is, an InterruptedException
is
thrown; otherwise the given IO
is executed as usual. Note that for IO
s supporting parallelism,
the thread that is checked for interruption may not necessarily be the same thread that the IO
ultimately
runs on.A
- the IO
result typeio
- the IO
to wrapIO
that first checks for thread interrupts
public static <A> IO<A> monitorSync(Object lock, IO<A> io)
IO
using the provided lock object. Note that to ensure that the entirety of the IO
's computation
actually runs inside the synchronized region, the IO
is executed
synchronously
inside the synchronized block regardless of the caller's chosen
execution strategy.public static <A> IO<A> fuse(IO<A> io)
IO
such that, unless it is pinned
(or is originally externally managed
), no parallelism will be used when
running it, regardless of what semantics are used when it is executed.A
- the IO
result typeio
- the IO
IO
pin(IO, Executor)
public static <A> IO<A> pin(IO<A> io, Executor executor)
IO
to an Executor
such that regardless of what future decisions are made, when it runs, it
will run using whatever parallelism is supported by the Executor
's threading model. Note that if this
IO
has already been pinned (or is originally externally managed
),
pinning to an additional Executor
has no meaningful effect.public static <A> IO<A> memoize(IO<A> io)
IO
, return an IO
that wraps it, caches its first successful result, and guarantees that
no subsequent interactions will happen with it afterwards, returning the cached result thereafter. Note that if
the underlying IO
throws, the failure will not be cached, so subsequent interactions with the memoized
IO
will again call through to the delegate until it completes normally.public static <A> IO<A> io(A a)
IO
that just returns a
when performed.A
- the result typea
- the resultIO
public static <A> IO<A> io(Fn0<? extends A> fn0)
IO
.A
- the result typefn0
- the lambda to coerceIO
public static IO<Unit> io(SideEffect sideEffect)
sideEffect
- the SideEffect
IO
public static <A> IO<A> externallyManaged(Fn0<CompletableFuture<A>> supplier)
IO
from an externally managed source of
completable futures
.
Note that constructing an IO
this way results in no intermediate futures being constructed by either
unsafePerformAsyncIO()
or unsafePerformAsyncIO(Executor)
, and unsafePerformIO()
is synonymous with invoking CompletableFuture.get()
on the externally managed future.
A
- the result typesupplier
- the source of externally managed completable futures
IO