Not recommended, you should generally prefer using Try.apply
instead
of instantiating a new Success or Failure directly.
Not recommended, you should generally prefer using Try.apply
instead
of instantiating a new Success or Failure directly.
Execute the given function and encapsulate the result in a Try, whether successful or not. If the func returns a value, this is returned encapsulated in a Success. If the func throws an error, it is captured in a Failure and returned.
The function to invoke.
Creates an operator for Observables in the style of rxjs. The operator will map an observable to one that emits tries: values will be mapped to successes encapsulating those values, and an error will be mapped to a failure encapsulating that error. The generated observable will terminate when the source observable terminate or errors.
The factory function
for creating a new Observable from a subscribe function. Note that this is not called with
new
, so if your function is a costructor, you'll need to encapsulate that in another function.
For instance, for rxjs, this could be (subscribe) => new rxjs.Observable(subscribe)
.
The subscribe
function that will be passed to Observable
is expected to be called
with an Observer
object that has next
, error
, and complete
methods.
The operator function which will take a source Observable
and return a derived Observable that emits Tries as described above. The source Observable passed
to the returned function is expected to have a subscribe
method which takes three arguments:
onNext, onError, and onComplete.
Similar to createTryOperator
, this returns an Observable operator
that unpacks Try values emitted by an observable. Encapsulated values of successes
are emitted as values, and a failure emitted by the source stream is unpacked and
its encapsulated error is put out as an error.
The factory function
for creating a new Observable from a subscribe function. Now that this is not called with
new
, so if your function is costructor, you'll need to encapsulate that in a function.
For instance, for rxjs, this could be (subscribe) => new rxjs.Observable(subscribe)
.
The subscribe
function that will be passed to Observable
is expected to be called
with an Observer
object that has next
, error
, and complete
methods.
The operator function which will take a source Observable
and return a derived Observable that emits Tries as described above. The source Observable passed
to the returned function is expected to have a subscribe
method which takes three arguments:
onNext, onError, and onComplete.
Similar to apply
, this executes a function and captures any exceptions thrown into
a Failure. The difference from apply
is that the given function is assumed to already
return a Try
, which is not wrapped in another Try
, but returned as is.
Converts a Maybe to a Try. Assumes the Maybe implements the map
and getOrElse
methods;
the former returns another Maybe with the encapsulated value (if any) transformed according to
the given function; the latter returns the encapsulated value or invokes the provided supplier
if the Maybe has no encapsulated value and returns the result.
A Maybe object
Convert a scala-like Option object to a Try. If the option is defined (as defined by it's
isDefined
method returning a truthy value), it's value (as returned by it's get
method)
is returned encapsulated in a success. Otherwise a Failure is returned.
Note that error thrown attempting to invoke the method of the option are not handled, they will
be thrown. The get
method is only invoked if isDefined
returns a truthy value.
An Option object.
Convert a java-like Optional object to a Try. If the optional is present (as defined by it's
isPresent
method returning a truthy value), it's value (as returned by it's get
method)
is returned encapsulated in a success. Otherwise a Failure is returned.
Note that error thrown attempting to invoke the method of the option are not handled, they will
be thrown. The get
method is only invoked if isPresent
returns a truthy value.
An Optional object.
Given a Promise for a value, returns a Promise for a Try of that value. The returned promise will always fulfill: if the given promise fulfills, the returned promise will fulfill with a success encapsulating the fulfillment value; if the given promise rejects, the returned promise will fulfill with a failure Try encapsulating the rejection error.
The promise to convert to a Try.
Generated using TypeDoc
An implementation of Try for representing successes.