hex.pm version CI GitHub code size in bytes

REnum

Many useful functions implemented. REnum is Enum extended with convenient functions inspired by Ruby and Rails ActiveSupport. It also provides full support for native functions through metaprogramming.

Installation

def deps do
  [
    {:r_enum, "~> 0.1"}
  ]
end

Usage

You can use all of Enum.Enumerable.* functions through REnum Module.

# Examples.
# REnum.Ruby.compact/1
iex> [1, nil, 2, 3]
iex> |> REnum.compact()
[1, 2, 3]
# REnum.Ruby.grep/2
iex> ["foo", "bar", "car", "moo"]
iex> |> REnum.grep(~r/ar/)
["bar", "car"]
# REnum.Ruby.each_slice/2
iex> [1, 2, 3, 4, 5, 6, 7]
iex> |> REnum.each_slice(3)
iex> |> REnum.to_list()
[[1, 2, 3], [4, 5, 6], [7]]
# REnum.ActiveSupport.pluck/2
iex> payments = [
...>   %Payment{dollars: 5, cents: 99},
...>   %Payment{dollars: 10, cents: 0},
...>   %Payment{dollars: 0, cents: 5}
...> ]
iex> |> REnum.pluck(:dollars)
[5, 10, 0]
# REnum.ActiveSupport.maximum/2
iex> REnum.maximum(payments, :dollars)
10
# REnum.ActiveSupport.without/2
iex> 1..5
iex> |> REnum.without([1, 5])
[2, 3, 4]

# RList.Ruby.combination/2
iex> [1, 2, 3, 4]
iex> RList.combination(3)
iex> |> Enum.to_list()
[[1,2,3],[1,2,4],[1,3,4],[2,3,4]]
# See also RList.Ruby.repeated_combination, RList.Ruby.permutation, RList.Ruby.repeated_permutation

iex> [:foo, 'bar', 2]
iex> |> RList.push([:baz, :bat])
[:foo, 'bar', 2, :baz, :bat]
# See also RList.Ruby.pop, RList.Ruby.shift, RList.Ruby.unshift

# Aliases.
# REnum.Ruby.select2
iex> [1, 2, 3]
iex> |> REnum.select(fn x -> rem(x, 2) == 0 end) ==
iex>   Enum.filter([1, 2, 3], fn x -> rem(x, 2) == 0 end)
true
# Can use Elixir's Enum functions too.
# REnum.Ruby.find/2
iex> [1, 2, 3]
iex> |> REnum.find(fn x -> rem(x, 2) == 1 end)
3
# REnum.Ruby.sort/1
iex> [1, 2, 3]
iex> REnum.sort()
[1, 2, 3]

For the full list of available functions, see API Reference.

Docs

See hexdocs.

Roadmap

  • [x] 0.1.0
    • REnum.Native
    • REnum.Ruby
    • REnum.Support
    • RList.Native
    • RMap.Native
    • RRange.Native
    • RStream.Native
    • RUtils
  • [x] 0.2.0
    • REnum.ActiveSupport
  • [ ] 0.4.0
    • RList.Ruby
  • [ ] 0.5.0
    • RList.ActiveSupport
  • [ ] 0.6.0
    • RMap.Ruby
    • RMap.ActiveSupport
  • [ ] 0.7.0
    • RRange.Ruby
    • RRange.ActiveSupport
  • [ ] 0.8.0
    • RStream.Ruby
    • RStream.ActiveSupport

Progress

REnumElixir ModuleRuby ClassElixirRubyActiveSupport
REnumEnumEnumerable
RListListArrayTODO
RMapMapHashTODOTODO
RRangeRangeRangeTODOTODO
RStreamStreamEnumerator::LazyTODOTODO