traverse v0.1.7 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

Link to this type t_simple_filter_fn()
t_simple_filter_fn() :: (any() -> boolean())
Link to this type t_simple_mapper_fn()
t_simple_mapper_fn() :: (any() -> any())
Link to this type t_simple_walker_fn()
t_simple_walker_fn() :: (any(), any() -> any())
Link to this type t_traceable_fn()
t_traceable_fn() ::
  (any() -> any())
  | (any(), any() -> any())
  | (any(), any(), any() -> any())

Link to this section Functions

Link to this function complete(partial_fn, with_fn)
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]

Link to this function complete_with_const(partial_fn, const \\ nil)
complete_with_const((any() -> any()), any()) :: (any() -> any())

Convenience function as described in doc of complete.

Link to this function complete_with_identity(partial_fn)
complete_with_identity((any() -> any())) :: (any() -> any())

Convenience function as described in doc of complete.

Link to this function complete_with_ignore(partial_fn)
complete_with_ignore((any() -> any())) :: (any() -> any())

Convenience function as described in doc of complete.

Link to this function identity()
identity() :: (any() -> any())

A convenience declaration of the identity function.

  iex> Traverse.Fn.identity().(42)
  42