|
| 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) | |
0 commit comments