RList.ActiveSupport (REnum v0.8.0)
Summarized all of List functions in Rails.ActiveSupport.
If a function with the same name already exists in Elixir, that is not implemented.
Defines all of here functions when use RList.ActiveSupport
.
Link to this section Summary
Functions
Equal to Enum.at(list, 4)
.
Equal to Enum.at(list, 41)
. Also known as accessing "the reddit".
Equal to Enum.at(list, 3)
.
Returns the tail of the list from position.
Splits or iterates over the list in number of groups, padding any remaining slots with fill_with unless it is false.
Splits or iterates over the list in groups of size number, padding any remaining slots with fill_with unless it is +false+.
Equal to Enum.at(list, 1)
.
Equal to Enum.at(list, -2)
.
Equal to Enum.at(list, 2)
.
Equal to Enum.at(list, -3)
.
Returns the beginning of the list up to position.
Converts the list to a comma-separated sentence where the last element is joined by the connector word.
Link to this section Functions
fifth(list)
Specs
Equal to Enum.at(list, 4)
.
Examples
iex> ~w[a b c d e]
iex> |> RList.fifth()
"e"
forty_two(list)
Specs
Equal to Enum.at(list, 41)
. Also known as accessing "the reddit".
Examples
iex> 1..42
iex> |> RList.forty_two()
42
fourth(list)
Specs
Equal to Enum.at(list, 3)
.
Examples
iex> ~w[a b c d]
iex> |> RList.fourth()
"d"
from(list, position)
Specs
Returns the tail of the list from position.
Examples
iex> ~w[a b c d]
iex> |> RList.from(0)
["a", "b", "c", "d"]
iex> ~w[a b c d]
iex> |> RList.from(2)
["c", "d"]
iex> ~w[a b c d]
iex> |> RList.from(10)
[]
iex> ~w[]
iex> |> RList.from(0)
[]
iex> ~w[a b c d]
iex> |> RList.from(-2)
["c", "d"]
iex> ~w[a b c d]
iex> |> RList.from(-10)
[]
in_groups(list, number, fill_with \\ nil)
Specs
in_groups(list(), non_neg_integer(), any() | nil) :: list()
Splits or iterates over the list in number of groups, padding any remaining slots with fill_with unless it is false.
Examples
iex> ~w[1 2 3 4 5 6 7 8 9 10]
iex> |> RList.in_groups(3)
[
["1", "2", "3", "4"],
["5", "6", "7", nil],
["8", "9", "10", nil]
]
iex> ~w[1 2 3 4 5 6 7 8 9 10]
iex> |> RList.in_groups(3, " ")
[
["1", "2", "3", "4"],
["5", "6", "7", " "],
["8", "9", "10", " "]
]
iex> ~w[1 2 3 4 5 6 7]
iex> |> RList.in_groups(3, false)
[
["1", "2", "3"],
["4", "5"],
["6", "7"]
]
in_groups_of(list, number, fill_with \\ nil)
Specs
in_groups_of(list(), non_neg_integer(), any() | nil) :: list()
Splits or iterates over the list in groups of size number, padding any remaining slots with fill_with unless it is +false+.
Examples
iex> ~w[1 2 3 4 5 6 7 8 9 10]
iex> |> RList.in_groups_of(3)
[
["1", "2", "3"],
["4", "5", "6"],
["7", "8", "9"],
["10", nil, nil]
]
iex> ~w[1 2 3 4 5]
iex> |> RList.in_groups_of(2, " ")
[
["1", "2"],
["3", "4"],
["5", " "]
]
iex> ~w[1 2 3 4 5]
iex> |> RList.in_groups_of(2, false)
[
["1", "2"],
["3", "4"],
["5"]
]
second(list)
Specs
Equal to Enum.at(list, 1)
.
Examples
iex> ~w[a b c d]
iex> |> RList.second()
"b"
second_to_last(list)
Specs
Equal to Enum.at(list, -2)
.
Examples
iex> ~w[a b c d e]
iex> |> RList.second_to_last()
"d"
third(list)
Specs
Equal to Enum.at(list, 2)
.
Examples
iex> ~w[a b c d]
iex> |> RList.third()
"c"
third_to_last(list)
Specs
Equal to Enum.at(list, -3)
.
Examples
iex> ~w[a b c d e]
iex> |> RList.third_to_last()
"c"
to(list, position)
Specs
Returns the beginning of the list up to position.
Examples
iex> ~w[a b c d]
iex> |> RList.to(0)
["a"]
iex> ~w[a b c d]
iex> |> RList.to(2)
["a", "b", "c"]
iex> ~w[a b c d]
iex> |> RList.to(10)
["a", "b", "c", "d"]
iex> ~w[]
iex> |> RList.to(0)
[]
iex> ~w[a b c d]
iex> |> RList.to(-2)
["a", "b", "c"]
iex> ~w[a b c d]
iex> |> RList.to(-10)
[]
to_default_s(list)
See Kernel.inspect/1
.
to_sentence(list, opts \\ [])
Specs
Converts the list to a comma-separated sentence where the last element is joined by the connector word.
You can pass the following options to change the default behavior. If you pass an option key that doesn't exist in the list below, it will raise an
Options
:words_connector
- The sign or word used to join all but the last element in lists with three or more elements (default: ", ").:last_word_connector
- The sign or word used to join the last element in lists with three or more elements (default: ", and ").:two_words_connector
- The sign or word used to join the elements in lists with two elements (default: " and ").
Examples
iex> ["one", "two"]
iex> |> RList.to_sentence()
"one and two"
iex> ["one", "two", "three"]
iex> |> RList.to_sentence()
"one, two, and three"
iex> ["one", "two"]
iex> |> RList.to_sentence(two_words_connector: "-")
"one-two"
iex> ["one", "two", "three"]
iex> |> RList.to_sentence(words_connector: " or ", last_word_connector: " or at least ")
"one or two or at least three"
iex> ["one", "two", "three"]
iex> |> RList.to_sentence()
"one, two, and three"