cat/instances/natural
Examples of transformations
between functors
.
Functions
pub fn list_length_transformation() -> NaturalTransformation(
Functor(ListF, a, b, List(a), List(b)),
Functor(ConstF(c), d, e, Const(c, d), Const(c, e)),
List(a),
Const(Int, f),
)
Natural transformation from List
to Const Int
.
Examples
[]
|> {list_length_transformation() |> transform()}
// -> Const(0)
[1, 2, 3, 4]
|> {list_length_transformation() |> transform()}
// -> Const(4)
pub fn list_option_head_transformation() -> NaturalTransformation(
Functor(ListF, a, b, List(a), List(b)),
Functor(OptionF, c, d, Option(c), Option(d)),
List(a),
Option(a),
)
Natural transformation from List
to Option
.
Examples
[]
|> {list_option_head_transformation() |> transform()}
// -> None
[1, 2, 3]
|> {list_option_head_transformation() |> transform()}
// -> Some(1)
pub fn option_list_transformation() -> NaturalTransformation(
Functor(OptionF, a, b, Option(a), Option(b)),
Functor(ListF, c, d, List(c), List(d)),
Option(a),
List(a),
)
Natural transformation from Option
to List
.
Examples
None
|> {option_list_transformation() |> transform()}
// -> []
Some(7)
|> {option_list_transformation() |> transform()}
// -> [7]