Skip to content

Commit fddb26d

Browse files
committed
Add more examples to filtering
1 parent 47d3a18 commit fddb26d

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

lib/elixir/pages/cheatsheets/enum-cheat.cheatmd

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,6 @@ cart = [
1212

1313
Some examples use the [`string =~ part`](`=~/2`) operator, which checks the string on the left contains the part on the right.
1414

15-
## Filtering
16-
{: .col-2}
17-
18-
### [filter(enum, fun)](`Enum.filter/2`)
19-
20-
```elixir
21-
iex> Enum.filter(cart, &(&1.fruit =~ "o"))
22-
[
23-
%{fruit: "orange", count: 6}
24-
]
25-
```
26-
27-
### [reject(enum, fun)](`Enum.reject/2`)
28-
29-
```elixir
30-
iex> Enum.reject(cart, &(&1.fruit =~ "o"))
31-
[
32-
%{fruit: "apple", count: 3},
33-
%{fruit: "banana", count: 1}
34-
]
35-
```
36-
3715
## Predicates
3816
{: .col-2}
3917

@@ -96,6 +74,31 @@ iex> Enum.empty?([])
9674
true
9775
```
9876

77+
## Filtering
78+
{: .col-2}
79+
80+
### [filter(enum, fun)](`Enum.filter/2`)
81+
82+
```elixir
83+
iex> Enum.filter(cart, &(&1.fruit =~ "o"))
84+
[%{fruit: "orange", count: 6}]
85+
iex> Enum.filter(cart, &(&1.fruit =~ "e"))
86+
[
87+
%{fruit: "apple", count: 3},
88+
%{fruit: "orange", count: 6}
89+
]
90+
```
91+
92+
### [reject(enum, fun)](`Enum.reject/2`)
93+
94+
```elixir
95+
iex> Enum.reject(cart, &(&1.fruit =~ "o"))
96+
[
97+
%{fruit: "apple", count: 3},
98+
%{fruit: "banana", count: 1}
99+
]
100+
```
101+
99102
## Mapping
100103
{: .col-2}
101104

0 commit comments

Comments
 (0)