Skip to content

Commit ea70171

Browse files
committed
Stream Drills Exercise
1 parent 9347cdb commit ea70171

File tree

2 files changed

+147
-13
lines changed

2 files changed

+147
-13
lines changed

exercises/stream_drills.livemd

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# Stream Drills
2+
3+
```elixir
4+
Mix.install([
5+
{:youtube, github: "brooklinjazz/youtube"},
6+
{:hidden_cell, github: "brooklinjazz/hidden_cell"},
7+
{:tested_cell, github: "brooklinjazz/tested_cell"},
8+
{:utils, path: "#{__DIR__}/../utils"}
9+
])
10+
```
11+
12+
## Navigation
13+
14+
[Return Home](../start.livemd)<span style="padding: 0 30px"></span>
15+
[Report An Issue](https://github.com/DockYard-Academy/beta_curriculum/issues/new?assignees=&labels=&template=issue.md&title=)
16+
17+
## Stream Drills
18+
19+
Drills help you develop familiarity and muscle memory with syntax through repeated exercises. Unlike usual problems, Drills are not intended to develop problem solving skills, they are purely for developing comfort and speed.
20+
21+
This set of drills is for [Streams](../reading/streams.livemd) follow the instructions for each drill and complete them as quickly as you can.
22+
23+
## Stream.map/2
24+
25+
Use `Stream.map/2` to double elements in a range from `1..10`, then use `Enum.to_list/1` to convert the resulting stream into a list `[2, 4, 6, 8, 10, 12, 14, 16, 18, 20]`
26+
27+
```elixir
28+
29+
```
30+
31+
Use `Stream.map/2` and `Enum.to_list/1` to sum a list of tuple pairs `[{1, 1}, {2, 2}, {3, 3}]` into `[2, 4, 6]`.
32+
33+
```elixir
34+
35+
```
36+
37+
## Stream.filter/2
38+
39+
Use `Stream.filter/2` and `Enum.to_list/1` to filter even numbers from a range `1..10` to return `[2, 4, 6, 8, 10]`.
40+
41+
```elixir
42+
43+
```
44+
45+
Use `Stream.filter/2` and `Enum.to_list/1` to filter numbers greater than `5` from a range `1..10` to return `[6, 7, 8, 9, 10]`.
46+
47+
```elixir
48+
49+
```
50+
51+
## Stream.cycle/1
52+
53+
Use `Stream.cycle/1` with `Enum.take/2` to generate the list `[1, 2, 3, 1, 2, 3, 1, 2, 3]`.
54+
55+
```elixir
56+
57+
```
58+
59+
Use `Stream.cycle/1` with `Enum.take/2` to generate the list `["a", "b", "a", "b"]`
60+
61+
```elixir
62+
63+
```
64+
65+
## Stream.iterate/2
66+
67+
Use `Stream.iterate/2` and `Enum.take/2` to generate a list of numbers from `1` to `10`.
68+
69+
```elixir
70+
71+
```
72+
73+
Use `Stream.iterate/2` and `Enum.take/2` to generate a list of negative numbers from `0` to `-10`.
74+
75+
```elixir
76+
77+
```
78+
79+
Use `Stream.iterate/2` and `Enum.take/2` to generate a list of `1` to `10` to the power of 2 by multiplying each accumulator by 2. i.e. $1^2, 2^2, 3^2$
80+
81+
```elixir
82+
83+
```
84+
85+
## Stream.unfold/2
86+
87+
Use `Stream.unfold/2` and `Enum.take/2` to generate a list of `10` cubed numbers. i.e. $1^2, 2^2, 3^2$
88+
89+
```elixir
90+
91+
```
92+
93+
Use `Stream.unfold/2` and `Enum.take/2` to generate a list of `5` integers as strings. `["1", "2", "3", "4", "5"]`.
94+
95+
```elixir
96+
97+
```
98+
99+
Use `Stream.unfold/2` and `Enum.take/2` to generate a list of integers from `1` to `10` divided by `2`.
100+
101+
```elixir
102+
103+
```
104+
105+
## Stream.chunk_every/2
106+
107+
Use `Stream.chunk_every/2` with `Enum.to_list/1` to chunk `[1, 1, 2, 2, 3, 3]` into `[[1, 1], [2, 2], [3, 3], [4, 4]]`
108+
109+
```elixir
110+
111+
```
112+
113+
Use `Stream.chunk_every/2` to chunk `[1, 1, 1, 2, 2, 2]` into `[[1, 1, 1], [2, 2, 2]]`
114+
115+
```elixir
116+
117+
```
118+
119+
Use `Stream.chunk_every/2` to chunk `[1, 2, 2, 1, 4, 4]` into pairs, then use `Stream.map/2` to sum the pairs together to make `[3, 3, 8]`.
120+
121+
## Commit Your Progress
122+
123+
Run the following in your command line from the beta_curriculum folder to track and save your progress in a Git commit.
124+
125+
```
126+
$ git add .
127+
$ git commit -m "finish typespec drills exercise"
128+
```
129+
130+
## Up Next
131+
132+
| Previous | Next |
133+
| ------------------------------------------------------------------------------------------------------ | -------------------------------------------: |
134+
| [Games Documentation And Static Analysis](../exercises/games_documentation_and_static_analysis.livemd) | [Rubix Cube](../exercises/rubix_cube.livemd) |

start.livemd

+13-13
Original file line numberDiff line numberDiff line change
@@ -226,27 +226,27 @@ livebook server start.livemd
226226

227227
<!-- livebook:{"break_markdown":true} -->
228228

229-
### Documentation and Static Analysis
229+
### ExUnit With Mix Projects
230230

231231
* Reading
232-
* [Doctests](reading/doctests.livemd)
233-
* [Typespecs](reading/typespecs.livemd)
234-
* [ExDoc](reading/exdoc.livemd)
235-
* [Credo](reading/credo.livemd)
232+
* [Elixir-lang: import](https://elixir-lang.org/getting-started/alias-require-and-import.html#import)
233+
* [Elixir-lang: alias](https://elixir-lang.org/getting-started/alias-require-and-import.html#alias)
234+
* [ExUnit With Mix](reading/exunit_with_mix.livemd)
236235
* Exercises
237-
* [Games: Documentation and Static Analysis](exercises/games_documentation_and_static_analysis.livemd)
238-
* Drills: [Typespecs](exercises/typespec_drills.livemd)
236+
* [Games: Wordle Application](exercises/games_wordle.livemd)
239237

240238
<!-- livebook:{"break_markdown":true} -->
241239

242-
### ExUnit With Mix Projects
240+
### Documentation and Static Analysis
243241

244242
* Reading
245-
* [Elixir-lang: import](https://elixir-lang.org/getting-started/alias-require-and-import.html#import)
246-
* [Elixir-lang: alias](https://elixir-lang.org/getting-started/alias-require-and-import.html#alias)
247-
* [ExUnit With Mix](reading/exunit_with_mix.livemd)
243+
* [Doctests](reading/doctests.livemd)
244+
* [Typespecs](reading/typespecs.livemd)
245+
* [ExDoc](reading/exdoc.livemd)
246+
* [Credo](reading/credo.livemd)
248247
* Exercises
249-
* [Games: Wordle Application](exercises/games_wordle.livemd)
248+
* Drills: [Typespecs](exercises/typespec_drills.livemd)
249+
* [Games: Documentation and Static Analysis](exercises/games_documentation_and_static_analysis.livemd)
250250

251251
## OTP and Advanced Syntax
252252

@@ -290,7 +290,7 @@ livebook server start.livemd
290290
* Reading
291291
* [Streams](reading/streams.livemd)
292292
* Exercises
293-
* Drills: Streams
293+
* Drills: [Streams](exercises/stream_drills.livemd)
294294
* [Lazy Product Filters](exercises/lazy_product_filters.livemd)
295295

296296
<!-- livebook:{"break_markdown":true} -->

0 commit comments

Comments
 (0)