This does not (and by definition cannot) handle errors that happen during
construction of the Result, because those happen before this is called.
See tryOr and tryOrElse as well as the corresponding
Result.tryOr and Result.tryOrElse methods for synchronous functions.
Examples
Given an Ok, fromResult will produces a Resolved task.
import { fromResult } from'true-myth/task'; import { ok } from'true-myth/result';
Build a
Task<T, E>
from aResult<T, E>
.This does not (and by definition cannot) handle errors that happen during construction of the
Result
, because those happen before this is called. SeetryOr
andtryOrElse
as well as the correspondingResult.tryOr
andResult.tryOrElse
methods for synchronous functions.Examples
Given an
Ok
,fromResult
will produces aResolved
task.Likewise, given an
Err
,fromResult
will produces aRejected
task.It is often clearest to access the function via a namespace-style import:
As an alternative, it can be useful to rename the import: