RList.Ruby (REnum v0.8.0)

Summarized all of Ruby's Array functions. Functions corresponding to the following patterns are not implemented

  • When a function with the same name already exists in Elixir.
  • When a method name includes !.
  • &, *, +, -, <<, <=>, ==, [], []=.

Link to this section Summary

Functions

Returns the first element in list that is an List whose first key == obj

Returns [].

Returns Stream that is each repeated combinations of elements of given list. The order of combinations is indeterminate.

Calls the function with combinations of elements of given list; returns :ok. The order of combinations is indeterminate.

Returns differences between list1 and list2.

Finds and returns the element in nested elements that is specified by index and identifiers.

Returns true if list1 == list2.

Fills the list with the provided value. The filler can be either a function or a fixed value.

Returns the index of a specified element.

Returns true if the list1 and list2 have at least one element in common, otherwise returns false.

Returns a new list containing each element found both in list1 and in all of the given list2; duplicates are omitted.

Returns Stream that is each repeated permutations of elements of given list. The order of permutations is indeterminate.

Splits the list into the last n elements and the rest. Returns nil if the list is empty.

Appends trailing elements.

Returns the first element that is a List whose last element == the specified term.

Returns Stream that is each repeated combinations of elements of given list. The order of combinations is indeterminate.

Calls the function with each repeated combinations of elements of given list; returns :ok. The order of combinations is indeterminate.

Returns Stream that is each repeated permutations of elements of given list. The order of permutations is indeterminate.

Returns the index of the last element found in in the list. Returns nil if no match is found.

Rotate the list so that the element at count is the first element of the list.

Returns one or more random elements.

Splits the list into the first n elements and the rest. Returns nil if the list is empty.

Returns list.

Returns a new list by joining two lists, excluding any duplicates and preserving the order from the given lists.

Prepends elements to the front of the list, moving other elements upwards.

Returns a list containing the elements in list corresponding to the given selector(s). The selectors may be either integer indices or ranges.

Link to this section Types

Link to this type

type_enumerable()

Specs

type_enumerable() :: Enumerable.t()
Link to this type

type_pattern()

Specs

type_pattern() :: number() | String.t() | Range.t() | Regex.t()

Link to this section Functions

Link to this function

all_combination(list, length)

See RList.Ruby.repeated_combination/2.

Link to this function

all_combination(list, length, func)

See RList.Ruby.repeated_combination/3.

Link to this function

append(list, elements)

See RList.Ruby.push/2.

Link to this function

assoc(list, key)

Specs

assoc(list(), any()) :: any()

Returns the first element in list that is an List whose first key == obj:

Examples

iex> [{:foo, 0}, [2, 4], [4, 5, 6], [4, 5]]
iex> |> RList.assoc(4)
[4, 5, 6]

iex> [[:foo, 0], [2, 4], [4, 5, 6], [4, 5]]
iex> |> RList.assoc(1)
nil

iex> [[:foo, 0], [2, 4], %{a: 4, b: 5, c: 6}, [4, 5]]
iex> |> RList.assoc({:a, 4})
%{a: 4, b: 5, c: 6}

Specs

clear(list()) :: []

Returns [].

Examples

iex> [[:foo, 0], [2, 4], [4, 5, 6], [4, 5]]
iex> |> RList.clear()
[]
Link to this function

combination(list, length)

Specs

combination(list(), non_neg_integer()) :: type_enumerable()

Returns Stream that is each repeated combinations of elements of given list. The order of combinations is indeterminate.

Examples

iex> RList.combination([1, 2, 3, 4], 1)
iex> |> Enum.to_list()
[[1],[2],[3],[4]]

iex> RList.combination([1, 2, 3, 4], 3)
iex> |> Enum.to_list()
[[1,2,3],[1,2,4],[1,3,4],[2,3,4]]

iex> RList.combination([1, 2, 3, 4], 0)
iex> |> Enum.to_list()
[[]]

iex> RList.combination([1, 2, 3, 4], 5)
iex> |> Enum.to_list()
[]
Link to this function

combination(list, n, func)

Specs

combination(list(), non_neg_integer(), function()) :: :ok

Calls the function with combinations of elements of given list; returns :ok. The order of combinations is indeterminate.

Examples

iex> RList.combination([1, 2, 3, 4], 1, &(IO.inspect(&1)))
# [1]
# [2]
# [3]
# [4]
:ok

iex> RList.combination([1, 2, 3, 4], 3, &(IO.inspect(&1)))
# [1, 2, 3]
# [1, 2, 4]
# [1, 3, 4]
# [2, 3, 4]
:ok

iex> RList.combination([1, 2, 3, 4], 0, &(IO.inspect(&1)))
# []
:ok

iex> RList.combination([1, 2, 3, 4], 5, &(IO.inspect(&1)))
:ok
Link to this function

delete_if(list, func)

See Enum.reject/2.

Link to this function

difference(list1, list2)

Specs

difference(list(), list()) :: list()

Returns differences between list1 and list2.

Examples

iex> [0, 1, 1, 2, 1, 1, 3, 1, 1]
iex> |> RList.difference([1])
[0, 2, 3]

iex> [0, 1, 2]
iex> |> RList.difference([4])
[0, 1, 2]
Link to this function

dig(list, index, identifiers \\ [])

Specs

dig(list(), integer(), list()) :: any()

Finds and returns the element in nested elements that is specified by index and identifiers.

Examples

iex> [:foo, [:bar, :baz, [:bat, :bam]]]
iex> |> RList.dig(1)
[:bar, :baz, [:bat, :bam]]

iex> [:foo, [:bar, :baz, [:bat, :bam]]]
iex> |> RList.dig(1, [2])
[:bat, :bam]

iex> [:foo, [:bar, :baz, [:bat, :bam]]]
iex> |> RList.dig(1, [2, 0])
:bat

iex> [:foo, [:bar, :baz, [:bat, :bam]]]
iex> |> RList.dig(1, [2, 3])
nil
Link to this function

each_index(list, func)

See Enum.with_index/2.

Link to this function

eql?(list1, list2)

Specs

eql?(list(), list()) :: boolean()

Returns true if list1 == list2.

Examples

iex>  [:foo, 'bar', 2]
iex> |> RList.eql?([:foo, 'bar', 2])
true

iex>  [:foo, 'bar', 2]
iex> |> RList.eql?([:foo, 'bar', 3])
false
Link to this function

fill(list, filler_fun)

Specs

fill(list(), any()) :: list()

Fills the list with the provided value. The filler can be either a function or a fixed value.

Examples

iex> RList.fill(~w[a b c d], "x")
["x", "x", "x", "x"]

iex> RList.fill(~w[a b c d], "x", 0..1)
["x", "x", "c", "d"]

iex> RList.fill(~w[a b c d], fn _, i -> i * i end)
[0, 1, 4, 9]

iex> RList.fill(~w[a b c d], fn _, i -> i * 2 end, 0..1)
[0, 2, "c", "d"]
Link to this function

fill(list, filler_fun, fill_range)

Specs

fill(list(), any(), Range.t()) :: list()
Link to this function

index(list, func_or_pattern)

Specs

index(list(), type_pattern() | function()) :: any()

Returns the index of a specified element.

Examples

iex> [:foo, "bar", 2, "bar"]
iex> |> RList.index("bar")
1

iex> [2, 4, 6, 8]
iex> |> RList.index(5..7)
2

iex> [2, 4, 6, 8]
iex> |> RList.index(&(&1 == 8))
3
Link to this function

insert(list, index, element)

See List.insert_at/3.

See Kernel.inspect/1.

Link to this function

intersect?(list1, list2)

Specs

intersect?(list(), list()) :: boolean()

Returns true if the list1 and list2 have at least one element in common, otherwise returns false.

Examples

iex> [1, 2, 3]
iex> |> RList.intersect?([3, 4, 5])
true

iex> [1, 2, 3]
iex> |> RList.intersect?([5, 6, 7])
false
Link to this function

intersection(list1, list2)

Specs

intersection(list(), list()) :: list()

Returns a new list containing each element found both in list1 and in all of the given list2; duplicates are omitted.

Examples

iex> [1, 2, 3]
iex> |> RList.intersection([3, 4, 5])
[3]

iex> [1, 2, 3]
iex> |> RList.intersection([5, 6, 7])
[]

iex> [1, 2, 3]
iex> |> RList.intersection([1, 2, 3])
[1, 2, 3]
Link to this function

keep_if(list, func)

See Enum.filter/2.

See Enum.count/1.

Link to this function

permutation(list, length \\ nil)

Specs

permutation(list(), non_neg_integer() | nil) :: type_enumerable()

Returns Stream that is each repeated permutations of elements of given list. The order of permutations is indeterminate.

Examples

iex> RList.permutation([1, 2, 3], 1)
iex> |> Enum.to_list()
[[1],[2],[3]]

iex> RList.permutation([1, 2, 3], 2)
iex> |> Enum.to_list()
[[1,2],[1,3],[2,1],[2,3],[3,1],[3,2]]

iex> RList.permutation([1, 2, 3])
iex> |> Enum.to_list()
[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]

iex> RList.permutation([1, 2, 3], 0)
iex> |> Enum.to_list()
[[]]

iex> RList.permutation([1, 2, 3], 4)
iex> |> Enum.to_list()
[]
Link to this function

pop(list, count \\ 1)

Specs

pop(list(), integer()) :: {list(), list()} | nil

Splits the list into the last n elements and the rest. Returns nil if the list is empty.

Examples

iex> RList.pop([])
nil

iex> RList.pop(~w[-m -q -filename test.txt])
{["test.txt"], ["-m", "-q", "-filename"]}

iex> RList.pop(~w[-m -q -filename test.txt], 2)
{["-filename", "test.txt"], ["-m", "-q"]}
Link to this function

prepend(list, count \\ 1)

See RList.Ruby.shift/2.

Link to this function

push(list, elements_or_element)

Specs

push(list(), list() | any()) :: list()

Appends trailing elements.

Examples

iex> [:foo, 'bar', 2]
iex> |> RList.push([:baz, :bat])
[:foo, 'bar', 2, :baz, :bat]

iex> [:foo, 'bar', 2]
iex> |> RList.push(:baz)
[:foo, 'bar', 2, :baz]
Link to this function

rassoc(list, key)

Specs

rassoc([list() | tuple()], any()) :: list() | nil

Returns the first element that is a List whose last element == the specified term.

Examples

iex> [{:foo, 0}, [2, 4], [4, 5, 6], [4, 5]]
iex> |> RList.rassoc(4)
[2, 4]

iex> [{:foo, 0}, [2, 4], [4, 5, 6], [4, 5]]
iex> |> RList.rassoc(0)
{:foo, 0}

iex> [[1, "one"], [2, "two"], [3, "three"], ["ii", "two"]]
iex> |> RList.rassoc("two")
[2, "two"]

iex> [[1, "one"], [2, "two"], [3, "three"], ["ii", "two"]]
iex> |> RList.rassoc("four")
nil

iex> [] |> RList.rassoc(4)
nil

iex> [[]] |> RList.rassoc(4)
nil

iex> [{}] |> RList.rassoc(4)
nil
Link to this function

repeated_combination(list, length)

Specs

repeated_combination(list(), non_neg_integer()) :: type_enumerable()

Returns Stream that is each repeated combinations of elements of given list. The order of combinations is indeterminate.

Examples

iex> RList.repeated_combination([1, 2, 3], 1)
iex> |> Enum.to_list()
[[1], [2], [3]]

iex> RList.repeated_combination([1, 2, 3], 2)
iex> |> Enum.to_list()
[[1, 1], [1, 2], [1, 3], [2, 2], [2, 3], [3, 3]]

iex> RList.repeated_combination([1, 2, 3], 3)
iex> |> Enum.to_list()
[[1, 1, 1], [1, 1, 2], [1, 1, 3], [1, 2, 2], [1, 2, 3], [1, 3, 3], [2, 2, 2], [2, 2, 3], [2, 3, 3], [3, 3, 3]]

iex> RList.repeated_combination([1, 2, 3], 0)
iex> |> Enum.to_list()
[[]]

iex> RList.repeated_combination([1, 2, 3], 5)
iex> |> Enum.to_list()
[
  [1, 1, 1, 1, 1],
  [1, 1, 1, 1, 2],
  [1, 1, 1, 1, 3],
  [1, 1, 1, 2, 2],
  [1, 1, 1, 2, 3],
  [1, 1, 1, 3, 3],
  [1, 1, 2, 2, 2],
  [1, 1, 2, 2, 3],
  [1, 1, 2, 3, 3],
  [1, 1, 3, 3, 3],
  [1, 2, 2, 2, 2],
  [1, 2, 2, 2, 3],
  [1, 2, 2, 3, 3],
  [1, 2, 3, 3, 3],
  [1, 3, 3, 3, 3],
  [2, 2, 2, 2, 2],
  [2, 2, 2, 2, 3],
  [2, 2, 2, 3, 3],
  [2, 2, 3, 3, 3],
  [2, 3, 3, 3, 3],
  [3, 3, 3, 3, 3]
]
Link to this function

repeated_combination(list, n, func)

Specs

repeated_combination(list(), non_neg_integer(), function()) :: :ok

Calls the function with each repeated combinations of elements of given list; returns :ok. The order of combinations is indeterminate.

Examples

iex> RList.repeated_combination([1, 2, 3, 4], 2, &(IO.inspect(&1)))
# [1, 1]
# [1, 2]
# [1, 3]
# [2, 2]
# [2, 3]
# [3, 3]
:ok
Link to this function

repeated_permutation(list, length)

Specs

repeated_permutation(list(), non_neg_integer()) :: type_enumerable()

Returns Stream that is each repeated permutations of elements of given list. The order of permutations is indeterminate.

Examples

iex> RList.repeated_permutation([1, 2], 1)
iex> |> Enum.to_list()
[[1],[2]]

iex> RList.repeated_permutation([1, 2], 2)
iex> |> Enum.to_list()
[[1,1],[1,2],[2,1],[2,2]]

iex> RList.repeated_permutation([1, 2], 3)
iex> |> Enum.to_list()
[[1,1,1],[1,1,2],[1,2,1],[1,2,2],[2,1,1],[2,1,2],[2,2,1],[2,2,2]]

iex> RList.repeated_permutation([1, 2], 0)
iex> |> Enum.to_list()
[[]]
Link to this function

rindex(list, finder)

Specs

rindex(list(), any()) :: integer() | nil

Returns the index of the last element found in in the list. Returns nil if no match is found.

Examples

iex> RList.rindex(~w[a b b b c], "b")
3

iex> RList.rindex(~w[a b b b c], "z")
nil

iex> RList.rindex(~w[a b b b c], fn x -> x == "b" end)
3
Link to this function

rotate(list, count \\ 1)

Specs

rotate(list(), integer()) :: list()

Rotate the list so that the element at count is the first element of the list.

Examples

iex> RList.rotate(~w[a b c d])
["b", "c", "d", "a"]

iex> RList.rotate(~w[a b c d], 2)
["c", "d", "a", "b"]

iex> RList.rotate(~w[a b c d], -3)
["b", "c", "d", "a"]
Link to this function

sample(list, n \\ 1)

Returns one or more random elements.

Link to this function

shift(list, count \\ 1)

Specs

shift(list(), integer()) :: {list(), list()} | nil

Splits the list into the first n elements and the rest. Returns nil if the list is empty.

Examples

iex> RList.shift([])
nil

iex> RList.shift(~w[-m -q -filename])
{["-m"], ["-q", "-filename"]}

iex> RList.shift(~w[-m -q -filename], 2)
{["-m", "-q"], ["-filename"]}

See Enum.count/1.

Specs

to_ary(list()) :: list()

Returns list.

Examples

iex> RList.to_ary(["c", "d", "a", "b"])
["c", "d", "a", "b"]

See Kernel.inspect/1.

Link to this function

transpose(list_of_lists)

See List.zip/1.

Link to this function

union(list_a, list_b)

Specs

union(list(), list()) :: list()

Returns a new list by joining two lists, excluding any duplicates and preserving the order from the given lists.

Examples

iex> RList.union(["a", "b", "c"], [ "c", "d", "a"])
["a", "b", "c", "d"]

iex> ["a"] |> RList.union(["e", "b"]) |> RList.union(["a", "c", "b"])
["a", "e", "b", "c"]
Link to this function

unshift(list, prepend)

Specs

unshift(list(), any()) :: list()

Prepends elements to the front of the list, moving other elements upwards.

Examples

iex> RList.unshift(~w[b c d], "a")
["a", "b", "c", "d"]

iex> RList.unshift(~w[b c d], [1, 2])
[1, 2, "b", "c", "d"]
Link to this function

values_at(list, indices)

Specs

values_at(list(), [integer() | Range.t()] | Range.t()) :: list()

Returns a list containing the elements in list corresponding to the given selector(s). The selectors may be either integer indices or ranges.

Examples

iex> RList.values_at(~w[a b c d e f], [1, 3, 5])
["b", "d", "f"]

iex> RList.values_at(~w[a b c d e f], [1, 3, 5, 7])
["b", "d", "f", nil]

iex> RList.values_at(~w[a b c d e f], [-1, -2, -2, -7])
["f", "e", "e", nil]

iex> RList.values_at(~w[a b c d e f], [4..6, 3..5])
["e", "f", nil, "d", "e", "f"]

iex> RList.values_at(~w[a b c d e f], 4..6)
["e", "f", nil]