Module Relude_AsyncResult
AsyncResult
is a module containing a type t('a, 'e)
, which is basically an alias and specialization of AsyncData.t(result('a, 'e))
. This variant type can be used to represent the different states in which a data value can exist while being loaded asynchronously, with the possibility of either success ('a
) or failure ('e
).
Like Relude_AsyncData
, AsyncResult
is similar to the Elm RemoteData, with the following key difference:
AsyncResult
has aReloading(result('a, 'e))
case which can represent a scenario where you've previously loaded data, and are reloading it while retaining the current/previous value or error.
The map
, bimap
apply
, flatMap
/bind
, etc. functions have been specialized to operate on the innermost 'a
and 'e
types, so you rarely need to do nested pattern matches with this type.
type t('a, 'e)
= Relude_AsyncData.t(Pervasives.result('a, 'e))
;AsyncResult is a specialization of AsyncData that uses a
result
as the value type. This is useful for async data that may fail (for example, network requests and reading files).This type also implements map/apply/flatMap/etc. to operate on the innermost
'a
value (insideOk
).
let init: a e. t('a, 'e);
Constructs an Init value
let loading: a e. t('a, 'e);
Constructs a Loading value
let reloadingOk: a e. 'a => t('a, 'e);
Constructs a Reloading(Ok(_)) value
let reloadingError: a e. 'e => t('a, 'e);
Constructs a Reloading(Error(_)) value
let completeOk: a e. 'a => t('a, 'e);
Constructs a Complete(Ok(_)) value
let completeError: a e. 'e => t('a, 'e);
Constructs a Complete(Error(_)) value
let ok: a e. 'a => t('a, 'e);
AsyncResult.ok
is an alias forcompleteOk
.
let error: a e. 'e => t('a, 'e);
AsyncResult.error
is an alias forcompleteError
.
let isReloading: Relude_AsyncData.t('a) => bool;
Indicates if the AsyncResult is in the Reloading state with any value
let isComplete: Relude_AsyncData.t('a) => bool;
Indicates if the AsyncResult is in the Complete state with any value
let isBusy: Relude_AsyncData.t('a) => bool;
Indicates if the AsyncResult is in a working state (Loading or Reloading)
let isIdle: Relude_AsyncData.t('a) => bool;
Indicates if the AsyncResult is in a non-working state (Init or Complete)
let isNotEmpty: Relude_AsyncData.t('a) => bool;
Indicates if the AsyncResult is Reloading or Complete
let isOk: a e. t('a, 'e) => bool;
Indicates if the contained Result is in an Ok state for Reloading or Complete
let isError: a e. t('a, 'e) => bool;
Indicates if the contained Result is in an Error state for Reloading or Complete
let isReloadingOk: a e. t('a, 'e) => bool;
Indicates if AsyncResult is in a Reloading(Ok(_)) state
let isReloadingError: a e. t('a, 'e) => bool;
Indicates if AsyncResult is in a Reloading(Error(_)) state
let isCompleteOk: a e. t('a, 'e) => bool;
Indicates if AsyncResult is in a Complete(Ok(_)) state
let isCompleteError: a e. t('a, 'e) => bool;
Indicates if AsyncResult is in a Complete(Error(_)) state
let getOk: a e. t('a, 'e) => option('a);
Gets the value from a Reloading(Ok(_)) or Complete(Ok(_)) value, as an option
let getError: a e. t('a, 'e) => option('e);
Gets the value from a Reloading(Error(_)) or Complete(Error(_)) value, as an option
let getReloadingOk: a e. t('a, 'e) => option('a);
Gets the value from a Reloading(Ok(_)) value, as an option
let getReloadingError: a e. t('a, 'e) => option('e);
Gets the value from a Reloading(Error(_)) value, as an option
let getCompleteOk: a e. t('a, 'e) => option('a);
Gets the value from a Complete(Ok(_)) value, as an option
let getCompleteError: a e. t('a, 'e) => option('e);
Gets the value from a Complete(Error(_)) value, as an option
let toBusy: Relude_AsyncData.t('a) => Relude_AsyncData.t('a);
Indicates if the AsyncResult is in a working state (Loading or Reloading)
let toIdle: Relude_AsyncData.t('a) => Relude_AsyncData.t('a);
Indicates if the AsyncResult is in a non-working state (Init or Complete)
let map: a b e. ('a => 'b) => t('a, 'e) => t('b, 'e);
Maps a pure function over the value in a Reloading(Ok(_)) or Complete(Ok(_)) value
let mapError: a e1 e2. ('e1 => 'e2) => t('a, 'e1) => t('a, 'e2);
Maps a pure function over the value in a Reloading(Error(_)) or Complete(Error(_)) value
let tap: a e. (unit => unit) => (unit => unit) => (Pervasives.result('a, 'e) => unit) => (Pervasives.result('a, 'e) => unit) => t('a, 'e) => t('a, 'e);
Applies a side effect function for each case of the AsyncResult
let tapInit: a e. (unit => unit) => t('a, 'e) => t('a, 'e);
Applies a side-effect function if the value is Init
let tapLoading: a e. (unit => unit) => t('a, 'e) => t('a, 'e);
Applies a side-effect function if the value is Loading
let tapReloading: a e. (Pervasives.result('a, 'e) => unit) => t('a, 'e) => t('a, 'e);
Applies a side-effect function if the value is Reloading
let tapComplete: a e. (Pervasives.result('a, 'e) => unit) => t('a, 'e) => t('a, 'e);
Applies a side-effect function if the value is Complete
let tapEmpty: a e. (unit => unit) => t('a, 'e) => t('a, 'e);
Applies a side-effect function if the value is Init or Loading
let tapNotEmpty: a e. (Pervasives.result('a, 'e) => unit) => t('a, 'e) => t('a, 'e);
Applies a side-effect function if the value is Reloading or Complete
let tapByValue: a e. (unit => unit) => (Pervasives.result('a, 'e) => unit) => t('a, 'e) => t('a, 'e);
Applies a side effect function if the value is empty or not-empty
let tapOk: a e. ('a => unit) => t('a, 'e) => t('a, 'e);
Applies a side effect function if the value is Reloading or Complete Ok
let tapError: a e. ('e => unit) => t('a, 'e) => t('a, 'e);
Applies a side effect function if the value is Reloading or Complete Error
let apply: a b e. t('a => 'b, 'e) => t('a, 'e) => t('b, 'e);
Applies a wrapped function to a value in a Reloading(Ok(_)) or Complete(Ok(_)) value
let pure: a e. 'a => t('a, 'e);
Lifts a pure value into a Complete(Ok(_)) context
let bind: a b e. t('a, 'e) => ('a => t('b, 'e)) => t('b, 'e);
Applies a monadic function to the value in a Reloading(Ok(_)) or Complete(Ok(_)) value
let flatMap: a b e. ('a => t('b, 'e)) => t('a, 'e) => t('b, 'e);
Applies a monadic function to the value in a Reloading(Ok(_)) or Complete(Ok(_)) value
let fold: a e b. 'b => 'b => (Pervasives.result('a, 'e) => 'b) => (Pervasives.result('a, 'e) => 'b) => t('a, 'e) => 'b;
Folds an AsyncResult value into a value of a new type, by applying the appropriate function for each of the possible states.
let foldLazy: a e b. (unit => 'b) => (unit => 'b) => (Pervasives.result('a, 'e) => 'b) => (Pervasives.result('a, 'e) => 'b) => t('a, 'e) => 'b;
Folds an AsyncResult value into a value of a new type, by applying the appropriate function for each of the possible states.
let foldByValue: a e b. 'b => ('a => 'b) => ('e => 'b) => t('a, 'e) => 'b;
Folds an AsyncResult value into a value of a new type, by applying the appropriate function. The non-value Init/Loading constructors use the same function, the Reloading(Ok(_)) and Complete(Ok(_)) values use the same function and same for Reloading(Error(_)) and Complete(Error(_)).
let foldByValueLazy: a e b. (unit => 'b) => ('a => 'b) => ('e => 'b) => t('a, 'e) => 'b;
Folds an AsyncResult value into a value of a new type, by applying the appropriate function. The non-value Init/Loading constructors use the same function, the Reloading(Ok(_)) and Complete(Ok(_)) values use the same function and same for Reloading(Error(_)) and Complete(Error(_)).
let fromAsyncData: a e. Relude_AsyncData.t('a) => t('a, 'e);
Converts an AsyncData to an AsyncResult.
let toAsyncData: a. t('a, 'a) => Relude_AsyncData.t('a);
Converts an AsyncResult to an AsyncData (requires the value and error types to be the same).