ExAequoFn.NamedFn (ExAequoFn v0.1.3)

View Source

A function wrapper

Summary

Functions

Same as call(..., []), basically extracting fun

This can also curry into a function

Types

binary?()

@type binary?() :: maybe(binary())

either_t(error_t, ok_t)

@type either_t(error_t, ok_t) :: {:ok, ok_t} | {:error, error_t}

function_t()

@type function_t() :: (... -> any())

maybe(t)

@type maybe(t) :: nil | t

result_t(t)

@type result_t(t) :: {:ok, t} | :error

stream_t()

@type stream_t() :: %Stream{accs: term(), done: term(), enum: term(), funs: term()}

t()

@type t() :: %ExAequoFn.NamedFn{
  arity: non_neg_integer(),
  fun: function_t(),
  name: binary()
}

transformer_t()

@type transformer_t() :: (any() -> result_t(any()))

transformers_t()

@type transformers_t() :: [transformer_t()]

Functions

call(myself)

@spec call(t()) :: any()

Same as call(..., []), basically extracting fun

call(named_fn, value)

@spec call(t(), any()) :: any()

This can also curry into a function

  iex(1)> join3 = new(&Enum.join([&1, &2, &3], "-"), "joiner")
  ...(1)> join2 = call(join3, ~W[a])
  ...(1)> assert join2.(~W[b c]) == "a-b-c"

But be careful with arg sizes

  iex(2)> adder = new(&(&1 + &2))
  ...(2)> assert_raise(ArgumentError, fn -> call(adder, [1, 2, 3]) end)

new(fun, name \\ nil)

@spec new(function_t(), binary?()) :: t()