traverse v0.1.5 Traverse.Fn
Implements convenience functions, and function wrappers to complete partial functions.
The latter is done by catching FunctionClauseError
.
iex> partial = fn x when is_atom(x) -> to_string(x) end
...> complete = Traverse.Fn.complete(partial, fn x -> x + 1 end)
...> Enum.map([1, :a], complete)
[2, "a"]
Link to this section Summary
Functions
Allows to complete a partial function
Convenience function as described in doc of complete
Convenience function as described in doc of complete
Convenience function as described in doc of complete
A convenience declaration of the identity function
Link to this section Types
t_traceable_fn :: (any -> any) | (any, any -> any) | (any, any, any -> any)
Link to this section Functions
complete((any -> any), (any -> any)) :: (any -> any)
Allows to complete a partial function
iex> partial = fn x when is_number(x) -> x + 1 end
...> complete = Traverse.Fn.complete(partial, Traverse.Fn.identity())
...> Enum.map([1, :a, []], complete)
[2, :a, []]
There are common cases like this, and here are some convenience functions for them
complete_with_identity
iex> partial = fn x when is_number(x) -> x + 1 end …> complete = Traverse.Fn.complete_with_identity(partial) …> Enum.map([1, :a, []], complete) [2, :a, []]
complete_with_const
iex> partial = fn x when is_number(x) -> x + 1 end …> complete = Traverse.Fn.complete_with_const(partial, 32) …> Enum.map([1, :a, []], complete) [2, 32, 32]
Or with the default
iex> partial = fn x when is_number(x) -> x + 1 end …> complete = Traverse.Fn.complete_with_const(partial) …> Enum.map([1, :a, []], complete) [2, nil, nil]
complete_with_ignore
iex> partial = fn x when is_number(x) -> x + 1 end …> complete = Traverse.Fn.complete_with_ignore(partial) …> Enum.map([1, :a, []], complete) [2, Traverse.Ignore, Traverse.Ignore]
complete_with_const((any -> any), any) :: (any -> any)
Convenience function as described in doc of complete
.
complete_with_identity((any -> any)) :: (any -> any)
Convenience function as described in doc of complete
.
complete_with_ignore((any -> any)) :: (any -> any)
Convenience function as described in doc of complete
.
A convenience declaration of the identity function.
iex> Traverse.Fn.identity().(42)
42