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

Specs

fifth(list()) :: any()

Equal to Enum.at(list, 4).

Examples

iex> ~w[a b c d e]
iex> |> RList.fifth()
"e"
Link to this function

forty_two(list)

Specs

forty_two(list()) :: any()

Equal to Enum.at(list, 41). Also known as accessing "the reddit".

Examples

iex> 1..42
iex> |> RList.forty_two()
42

Specs

fourth(list()) :: any()

Equal to Enum.at(list, 3).

Examples

iex> ~w[a b c d]
iex> |> RList.fourth()
"d"
Link to this function

from(list, position)

Specs

from(list(), integer()) :: list()

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)
[]
Link to this function

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"]
]
Link to this function

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"]
]

Specs

second(list()) :: any()

Equal to Enum.at(list, 1).

Examples

iex> ~w[a b c d]
iex> |> RList.second()
"b"
Link to this function

second_to_last(list)

Specs

second_to_last(list()) :: any()

Equal to Enum.at(list, -2).

Examples

iex> ~w[a b c d e]
iex> |> RList.second_to_last()
"d"

Specs

third(list()) :: any()

Equal to Enum.at(list, 2).

Examples

iex> ~w[a b c d]
iex> |> RList.third()
"c"
Link to this function

third_to_last(list)

Specs

third_to_last(list()) :: any()

Equal to Enum.at(list, -3).

Examples

iex> ~w[a b c d e]
iex> |> RList.third_to_last()
"c"
Link to this function

to(list, position)

Specs

to(list(), integer()) :: list()

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)
[]
Link to this function

to_default_s(list)

See Kernel.inspect/1.

Link to this function

to_sentence(list, opts \\ [])

Specs

to_sentence(list(), [keyword()] | nil) :: String.t()

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"