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.
See Enum.count/1
.
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.
See Enum.count/1
.
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
type_enumerable()
Specs
type_enumerable() :: Enumerable.t()
type_pattern()
Specs
Link to this section Functions
all_combination(list, length)
all_combination(list, length, func)
append(list, elements)
See RList.Ruby.push/2
.
assoc(list, key)
Specs
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}
clear(list)
Specs
clear(list()) :: []
Returns [].
Examples
iex> [[:foo, 0], [2, 4], [4, 5, 6], [4, 5]]
iex> |> RList.clear()
[]
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()
[]
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
delete_if(list, func)
See Enum.reject/2
.
difference(list1, list2)
Specs
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]
dig(list, index, identifiers \\ [])
Specs
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
each_index(list, func)
See Enum.with_index/2
.
eql?(list1, list2)
Specs
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
fill(list, filler_fun)
Specs
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"]
fill(list, filler_fun, fill_range)
Specs
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
insert(list, index, element)
See List.insert_at/3
.
inspect(list)
See Kernel.inspect/1
.
intersect?(list1, list2)
Specs
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
intersection(list1, list2)
Specs
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]
keep_if(list, func)
See Enum.filter/2
.
length(list)
See Enum.count/1
.
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()
[]
pop(list, count \\ 1)
Specs
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"]}
prepend(list, count \\ 1)
See RList.Ruby.shift/2
.
push(list, elements_or_element)
Specs
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]
rassoc(list, key)
Specs
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
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]
]
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
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()
[[]]
rindex(list, finder)
Specs
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
rotate(list, count \\ 1)
Specs
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"]
sample(list, n \\ 1)
Returns one or more random elements.
shift(list, count \\ 1)
Specs
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"]}
size(list)
See Enum.count/1
.
to_ary(list)
Specs
Returns list.
Examples
iex> RList.to_ary(["c", "d", "a", "b"])
["c", "d", "a", "b"]
to_s(list)
See Kernel.inspect/1
.
transpose(list_of_lists)
See List.zip/1
.
union(list_a, list_b)
Specs
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"]
unshift(list, prepend)
Specs
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"]
values_at(list, indices)
Specs
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]