ListToCsv.Key (list_to_csv v1.1.1) View Source
ListToCsv.Key
contains types and utilities for keys.
Link to this section Summary
Functions
build prefix keys with trailing :N
Returns a list of keys
duplicated n
times. And replace first :N
with current 1 base index.
Returns a new list created by replacing occurrences of from
in subject
with to
. Only the first occurrence is replaced.
Returns true
if keys
starts with the given prefix
list; otherwise returns
false
.
Link to this section Types
Specs
Specs
Link to this section Functions
Specs
build prefix keys with trailing :N
Examples
iex> build_prefix(:name)
[:name, :N]
iex> build_prefix([:item, :name])
[:item, :name, :N]
Specs
Returns a list of keys
duplicated n
times. And replace first :N
with current 1 base index.
Examples
iex> duplicate([[:name, :N]], 2)
[[:name, 1], [:name, 2]]
iex> duplicate([[:name, :N, :item, :N]], 2)
[[:name, 1, :item, :N], [:name, 2, :item, :N]]
iex> duplicate([{&(&1 + &2), [[:item, :N, :quantity], :capacity]}], 2)
[{&(&1 + &2), [[:item, 1, :quantity], :capacity]},
{&(&1 + &2), [[:item, 2, :quantity], :capacity]}]
Specs
Returns a new list created by replacing occurrences of from
in subject
with to
. Only the first occurrence is replaced.
Examples
iex> replace_first(:item, :N, 1)
:item
iex> replace_first([:item], :N, 1)
[:item]
iex> replace_first([:item, :N, :name], :N, 1)
[:item, 1, :name]
iex> replace_first([:item, :N, :name, :N], :N, 2)
[:item, 2, :name, :N]
iex> replace_first({&(&1 + &2), [[:item, :N, :quantity], :capacity]}, :N, 3)
{&(&1 + &2), [[:item, 3, :quantity], :capacity]}
Specs
Returns true
if keys
starts with the given prefix
list; otherwise returns
false
.
Note that :N
can match with integer
.
Examples
iex> starts_with?(:name, [:item, :N])
false
iex> starts_with?([:item, :N, :name], [:item, :N])
true
iex> starts_with?([:name], [:item, :N])
false
iex> starts_with?([:item, 1, :name, :N, :first], [:item, :N, :name, :N])
true
iex> starts_with?([:packages, :N, :name], [:item, :N])
false
iex> starts_with?({&(&1 + &2), [[:item, :N, :quantity], :capacity]}, [:item, :N])
true