|
7 | 7 |
|
8 | 8 | defimpl ElixirScript.Enumerable, for: List do |
9 | 9 | def count(list), |
10 | | - do: {:ok, length(list) } |
| 10 | + do: {:ok, list.length } |
11 | 11 |
|
12 | 12 | def member?(list, value), |
13 | 13 | do: {:ok, value in list } |
14 | 14 |
|
15 | | - def reduce(_, {:halt, acc}, _fun), do: {:halted, acc} |
16 | | - def reduce(list, {:suspend, acc}, fun), do: {:suspended, acc, &reduce(list, &1, fun)} |
17 | | - def reduce([], {:cont, acc}, _fun), do: {:done, acc} |
18 | | - def reduce([h | t], {:cont, acc}, fun), do: reduce(t, fun.(h, acc), fun) |
| 15 | + def reduce(list, acc, fun), do |
| 16 | + Bootstrap.Core.Functions.iterator_to_reducer(list, acc, fun) |
| 17 | + end |
19 | 18 | end |
20 | 19 |
|
21 | 20 | defimpl ElixirScript.Enumerable, for: Map do |
22 | 21 | def count(map) do |
23 | | - {:ok, map_size(map)} |
| 22 | + {:ok, map.length} |
24 | 23 | end |
25 | 24 |
|
26 | 25 | def member?(map, {key, value}) do |
27 | | - {:ok, match?(^value, Map.get(map, key))} |
| 26 | + {:ok, Map.get(map, key) == value } |
28 | 27 | end |
29 | 28 |
|
30 | 29 | def member?(_, _) do |
31 | 30 | {:ok, false} |
32 | 31 | end |
33 | 32 |
|
34 | 33 | def reduce(map, acc, fun) do |
| 34 | + map |
| 35 | + |> Map.to_list |
| 36 | + |> Bootstrap.Core.Functions.iterator_to_reducer(acc, fun) |
35 | 37 | do_reduce(Map.to_list(map), acc, fun) |
36 | 38 | end |
37 | | - |
38 | | - defp do_reduce(_, {:halt, acc}, _fun), do: {:halted, acc} |
39 | | - defp do_reduce(list, {:suspend, acc}, fun), do: {:suspended, acc, &do_reduce(list, &1, fun)} |
40 | | - defp do_reduce([], {:cont, acc}, _fun), do: {:done, acc} |
41 | | - defp do_reduce([h | t], {:cont, acc}, fun), do: do_reduce(t, fun.(h, acc), fun) |
42 | 39 | end |
0 commit comments