Maybe
is a structure for values that may not be present or for situations that may fail. A Maybe
can help in dealing with optional values, arguments, records with optional fields, etc.
Implements: Alt
, Monad
, Semigroup
, Setoid
Creates a Just v
.
Param | Type | Description |
---|---|---|
v | any |
Value |
Creates a Nothing
.
Creates a Just v
.
Param | Type | Description |
---|---|---|
v | any |
Value |
Creates a Nothing
.
Creates a Just
if the value is not null
or undefined
; otherwise, creates a Nothing
.
Param | Type | Description |
---|---|---|
v | any |
Value |
Creates a Just
if the value v
is not null
or undefined
; otherwise, creates a Just
with the default value def
.
Param | Type | Description |
---|---|---|
def | any |
Default value |
v | any |
Value |
A static method that takes an array of Maybe
values and returns an array of the values of all the Just
elements in the passed array.
Param | Type | Description |
---|---|---|
ar | Array.<any> |
Array of Maybe values |
A static method that returns true
if the passed Maybe
is a Nothing
.
Param | Type | Description |
---|---|---|
v | any |
Maybe |
A static method that returns true
if the passed Maybe
is a Just
.
Param | Type | Description |
---|---|---|
v | any |
Maybe |
Returns true
if the current and the passed elements are of the Maybe
type with the same value.
Param | Type | Description |
---|---|---|
n | any |
Any value of type Setoid |
Applies the passed function to the value of the current Maybe
if it is a Just
.
Param | Type | Description |
---|---|---|
f | function |
Function |
Chains together many computations that return a Maybe
type.
Param | Type | Description |
---|---|---|
f | function |
Function that returns another Maybe |
Returns true
if the current Maybe
is a Nothing
.
Returns true
if the current Maybe
is a Just
.
An instance method that returns the current Maybe
if it is a Just
; otherwise, returns the passed Maybe
.
Param | Type | Description |
---|---|---|
v | any |
Maybe |
Applies the function inside the passed Maybe
to the current Maybe
if it is a Just
.
Param | Type | Description |
---|---|---|
j | any |
Maybe with a function |
Gets the value within the Maybe
.