Current section

Files

Jump to
cliex_map lib cliex_map fn.ex
Raw

lib/cliex_map/fn.ex

defmodule CliexMap.Fn do
use CliexMap.Types
alias CliexMap.Context
@moduledoc ~S"""
A simple wrapper around functions for readability
"""
defstruct function: nil, name: "a function"
@type fn_result_t ::{any(), Context.t()} | any()
@type fn_t :: (any(), maybe(Context.t()) -> fn_result_t())
@type t :: %__MODULE__{function: fn_t(), name: binary()}
@spec call(t(), any(), maybe(Context.t)) :: fn_result_t()
def call(%__MODULE__{function: function}, value, context \\ nil), do: function.(value, context)
# @spec new(fn_t(), binary()) :: t()
def new(a_function, a_name), do: %__MODULE__{function: a_function, name: a_name}
end
# SPDX-License-Identifier: Apache-2.0