Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RList.ActiveSupport #25

Merged
merged 9 commits into from
Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: CI
on: [push, pull_request]
on: [push]
jobs:
native_test:
name: OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}}
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

# Changelog

## v0.5.0 (2022-1-26)

### Features

- RList.ActiveSupport

## v0.4.0 (2022-1-24)

### Features
Expand Down
41 changes: 33 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,18 @@ You can use all of `Enum.Enumerable.*` functions through REnum Module.
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},
Expand All @@ -47,9 +50,7 @@ iex> payments = [
...> ]
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])
Expand All @@ -62,25 +63,45 @@ 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

# RList.Ruby.push/2
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

# RList.ActiveSupport.second/1
iex> [:foo, 'bar', 2]
iex> |> RList.second()
'bar'
# See also RList.ActiveSupport.second, RList.ActiveSupport.third, RList.ActiveSupport.fourth, RList.ActiveSupport.fifth, RList.ActiveSupport.forty_two

# RList.ActiveSupport.from/2
iex> ~w[a b c d]
iex> |> RList.from(2)
["c", "d"]
# See also RList.ActiveSupport.to

# RList.ActiveSupport.to_sentence/2
iex> ["one", "two", "three"]
iex> |> RList.to_sentence(words_connector: " or ", last_word_connector: " or at least ")
"one or two or at least three"

# Aliases.
# REnum.Ruby.select2
# REnum.Ruby.select/2
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)
...> 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()
iex> |> REnum.sort()
[1, 2, 3]
```

Expand All @@ -105,7 +126,7 @@ See **[hexdocs](https://hexdocs.pm/r_enum)**.
- REnum.ActiveSupport
- [x] 0.4.0
- RList.Ruby
- [ ] 0.5.0
- [x] 0.5.0
- RList.ActiveSupport
- [ ] 0.6.0
- RMap.Ruby
Expand All @@ -114,6 +135,10 @@ See **[hexdocs](https://hexdocs.pm/r_enum)**.
- RRange.Ruby
- RRange.ActiveSupport
- [ ] 0.8.0
- to_param
- to_query
- to_xml
- [ ] 0.9.0
- RStream.Ruby
- RStream.ActiveSupport

Expand All @@ -122,7 +147,7 @@ See **[hexdocs](https://hexdocs.pm/r_enum)**.
| REnum | Elixir Module | Ruby Class | Elixir | Ruby | ActiveSupport |
| ------- | ------------- | ---------------- | :----: | :--: | :-----------: |
| REnum | Enum | Enumerable | ✅ | ✅ | ✅ |
| RList | List | Array | ✅ | ✅ | TODO |
| RList | List | Array | ✅ | ✅ | |
| RMap | Map | Hash | ✅ | TODO | TODO |
| RRange | Range | Range | ✅ | TODO | TODO |
| RStream | Stream | Enumerator::Lazy | ✅ | TODO | TODO |
1 change: 1 addition & 0 deletions lib/r_enum.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ defmodule REnum do
See also
- [REnum.Native](https://hexdocs.pm/r_enum/REnum.Native.html#content)
- [REnum.Ruby](https://hexdocs.pm/r_enum/REnum.Ruby.html#content)
- [REnum.ActiveSupport](https://hexdocs.pm/r_enum/REnum.ActiveSupport.html#content)
- [REnum.Support](https://hexdocs.pm/r_enum/REnum.Support.html#content)
"""
defmacro __using__(opts) do
Expand Down
4 changes: 2 additions & 2 deletions lib/r_enum/active_support.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule REnum.ActiveSupport do
@moduledoc """
Summarized all of Enumerable 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 RUtils`.
Defines all of here functions when `use ActiveSupport`.
"""
@spec __using__(any) :: list
defmacro __using__(_opts) do
Expand All @@ -20,7 +20,7 @@ defmodule REnum.ActiveSupport do
# https://www.rubydoc.info/gems/activesupport/Enumerable
# ruby_enumerable = [:as_json, :compact_blank, :exclude?, :excluding, :in_order_of, :including, :index_by, :index_with, :many?, :maximum, :minimum, :pick, :pluck, :sole, :without]
# |> RUtils.required_functions([Enum])
# as_json
# × as_json
# ✔ compact_blank
# ✔ exclude?
# ✔ excluding
Expand Down
2 changes: 2 additions & 0 deletions lib/r_list.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ defmodule RList do
See also.
- [RList.Native](https://hexdocs.pm/r_enum/RList.Native.html#content)
- [RList.Ruby](https://hexdocs.pm/r_enum/RList.Ruby.html#content)
- [RList.ActiveSupport](https://hexdocs.pm/r_enum/RList.ActiveSupport.html#content)
- [REnum](https://hexdocs.pm/r_enum/REnum.html#content)
"""
use RList.Native
use RList.Ruby
use RList.ActiveSupport
use RList.Support
use REnum, undelegate_functions: List.module_info()[:exports] |> Keyword.keys()
end
Loading