Swiss (swiss v3.12.0) View Source
Swiss
Swiss is a bundle of extensions to the standard lib. It includes several helper functions for dealing with standard types.
API
The root module has generic helper functions; check each sub-module's docs for each type's API.
Link to this section Summary
Functions
Applies the given apply_fn
to the given value
if the given predicate_fn
returns true.
Applies the given apply_fn
to the given value
unless the given
predicate_fn
returns true.
More idiomatic !is_nil/1
. Defined as a macro so it can be used in guards.
Wrapper that makes any function usable directly in Kernel.get_in/2
.
Applies the given func
to value
and returns value.
Applies the given func
to value
and returns its result.
Link to this section Functions
Specs
apply_if( value :: any(), apply_fn :: (any() -> any()), predicate_fn :: (any() -> boolean()) ) :: any()
Applies the given apply_fn
to the given value
if the given predicate_fn
returns true.
By default, predicate_fn
is is_present/1
.
Examples
iex> Swiss.apply_if(42, &(&1 + 8))
50
iex> Swiss.apply_if(42, &(&1 + 8), &(&1 > 40))
50
iex> Swiss.apply_if(42, &(&1 + 8), &(&1 < 40))
42
iex> Swiss.apply_if(42, &(&1 + 8), true)
50
iex> Swiss.apply_if(42, &(&1 + 8), false)
42
Specs
apply_unless( value :: any(), apply_fn :: (any() -> any()), predicate_fn :: (any() -> boolean()) ) :: any()
Applies the given apply_fn
to the given value
unless the given
predicate_fn
returns true.
By default, predicate_fn
is is_nil/1
.
Examples
iex> Swiss.apply_unless(nil, &(&1 + 8))
nil
iex> Swiss.apply_unless(42, &(&1 + 8))
50
iex> Swiss.apply_unless(42, &(&1 + 8), &(&1 > 40))
42
iex> Swiss.apply_unless(42, &(&1 + 8), &(&1 < 40))
50
iex> Swiss.apply_unless(42, &(&1 + 8), false)
50
iex> Swiss.apply_unless(42, &(&1 + 8), true)
42
More idiomatic !is_nil/1
. Defined as a macro so it can be used in guards.
Examples
iex> Swiss.is_present(nil)
false
iex> Swiss.is_present([])
true
iex> Swiss.is_present(42)
true
Wrapper that makes any function usable directly in Kernel.get_in/2
.
Examples
iex> get_in([%{"life" => 42}], [Swiss.nextable(&List.first/1), "life"])
42
Specs
Applies the given func
to value
and returns value.
Examples
iex> Swiss.tap(42, &(12 + &1))
42
Specs
Applies the given func
to value
and returns its result.
Examples
iex> Swiss.thru(42, &(12 + &1))
54