Realm v0.1.0 Realm.Functor protocol View Source
Functors are datatypes that allow the application of functions to their interior values. Always returns data in the same structure (same size, tree layout, and so on). Please note that bitstrings are not functors, as they fail the functor composition constraint. They change the structure of the underlying data, and thus composed lifting does not equal lifing a composed function. If you need to map over a bitstring, convert it to and from a charlist.
Type Class
An instance of Realm.Functor
must define Realm.Functor.map/2
.
Functor [map/2]
Link to this section Summary
Functions
map
a function into one layer of a data wrapper.
There is an autocurrying variant: lift/2
.
Link to this section Types
Link to this section Functions
map
a function into one layer of a data wrapper.
There is an autocurrying variant: lift/2
.
Examples
iex> Realm.Functor.map([1, 2, 3], fn x -> x + 1 end)
[2, 3, 4]
iex> %{a: 1, b: 2} ~> fn x -> x * 10 end
%{a: 10, b: 20}
iex> Realm.Functor.map(%{a: 2, b: [1, 2, 3]}, fn
...> int when is_integer(int) -> int * 100
...> value -> inspect(value)
...> end)
%{a: 200, b: "[1, 2, 3]"}