Functor
public protocol Functor : Invariant
A Functor provides a type with the ability to transform its value type into another type, while preserving its structure.
Using the encoding for HKTs in Bow, in the type Kind<F, A>, A is the value type and F represents the structure of the type. An instance of Functor for F allows to transform A into another type, while maintaining F unchanged.
-
Creates a new value transforming the type using the provided function, preserving the structure of the original type.
The implementation of this function must obey two laws:
Preserve identity:
map(fa, id) == faPreserve composition:
map(map(fa, f), g) == map(fa, compose(g, f))
Declaration
Parameters
faA value in the context of the type implementing this instance of
Functor.fA transforming function.
Return Value
The result of transforming the value type using the provided function, maintaining the structure of the original value.
-
hylo(_:_:_:)Extension method
-
imap(_:_:_:)Extension method -
lift(_:)Extension methodGiven a function, provides a new function lifted to the context type implementing this instance of
Functor.Declaration
Parameters
fFunction to be lifted.
Return Value
Function in the context implementing this instance of
Functor. -
void(_:)Extension method -
fproduct(_:_:)Extension methodTransforms the value type and pairs it with its original value.
Declaration
Parameters
faValue to be transformed.
fTransforming function.
Return Value
A pair with the original value and its transformation, in the context of the original value.
-
as(_:_:)Extension methodTransforms the value type with a constant value.
Parameters
faValue to be transformed.
bConstant value to replace the value type.
Return Value
A new value with the structure of the original value, with its value type transformed.
-
tupleLeft(_:_:)Extension methodTransforms the value type by making a tuple with a new constant value to the left of the original value type.
Parameters
faValue to be transformed.
bConstant value for the tuple.
Return Value
A new value with the structure of the original value, with a tuple in its value type.
-
tupleRight(_:_:)Extension methodTransforms the value type by making a tuple with a new constant value to the right of the original value type.
Parameters
faValue to be transformed.
bConstant value for the tuple.
Return Value
A new value with the structure of the original value, with a tuple in its value type.
Install in Dash
Functor Protocol Reference