Create an instance of Ok
.
Note: While you may create the Result
type via normal
JavaScript class construction, it is not recommended for the functional
style for which the library is intended. Instead, use ok
.
// Avoid:
const aString = new Result.Ok('characters');
// Prefer:
const aString = Result.ok('characters);
Note that you may explicitly pass Unit
to the Ok
constructor to create a Result<Unit, E>
. However, you may not call the
Ok
constructor with null
or undefined
to get that result (the type
system won't allow you to construct it that way). Instead, for convenience,
you can simply call ok
, which will construct the type correctly.
Create an instance of Ok
.
Note: While you may create the Result
type via normal
JavaScript class construction, it is not recommended for the functional
style for which the library is intended. Instead, use ok
.
// Avoid:
const aString = new Result.Ok('characters');
// Prefer:
const aString = Result.ok('characters);
Note that you may explicitly pass Unit
to the Ok
constructor to create a Result<Unit, E>
. However, you may not call the
Ok
constructor with null
or undefined
to get that result (the type
system won't allow you to construct it that way). Instead, for convenience,
you can simply call ok
, which will construct the type correctly.
The value to wrap in an Ok
.
Create an instance of
Ok
.If you need to create an instance with a specific type (as you do whenever you are not constructing immediately for a function return or as an argument to a function), you can use a type parameter:
Note: passing nothing, or passing
null
orundefined
explicitly, will produce aResult<Unit, E>
, rather than producing the nonsensical and in practice quite annoyingResult<null, string>
etc. SeeUnit
for more.In the context of an immediate function return, or an arrow function with a single expression value, you do not have to specify the types, so this can be quite convenient.
Template: T
The type of the item contained in the
Result
.Param: value
The value to wrap in a
Result.Ok
.