Skip to content

Latest commit

 

History

History
178 lines (113 loc) · 6.63 KB

stream_drills.livemd

File metadata and controls

178 lines (113 loc) · 6.63 KB

Stream Drills

Mix.install([
  {:jason, "~> 1.4"},
  {:kino, "~> 0.9", override: true},
  {:youtube, github: "brooklinjazz/youtube"},
  {:hidden_cell, github: "brooklinjazz/hidden_cell"}
])

Navigation

Stream Drills

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.

This set of drills is for Streams. Follow the instructions for each drill and complete them as quickly as you can.

Stream.map/2

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]

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].

Stream.filter/2

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].

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].

Stream.cycle/1

Use Stream.cycle/1 with Enum.take/2 to generate the list [1, 2, 3, 1, 2, 3, 1, 2, 3].

Use Stream.cycle/1 with Enum.take/2 to generate the list ["a", "b", "a", "b"]

Stream.iterate/2

Use Stream.iterate/2 and Enum.take/2 to generate a list of numbers from 1 to 10.

Use Stream.iterate/2 and Enum.take/2 to generate a list of negative numbers from 0 to -10.

Use Stream.iterate/2 and Enum.take/2 to generate a list of 2 to increasing powers by multiplying the accumulator by two. i.e. $2^1$, $2^2$, $2^3$, $2^4$.

Stream.unfold/2

Use Stream.unfold/2 and Enum.take/2 to generate a list of 10 cubed numbers. i.e. $1^3, 2^3, 3^3$

Use Stream.unfold/2 and Enum.take/2 to generate a list of 5 integers as strings. ["1", "2", "3", "4", "5"].

Use Stream.unfold/2 and Enum.take/2 to generate a list of integers from 1 to 10 divided by 2.

Stream.chunk_every/2

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]]

Use Stream.chunk_every/2 to chunk [1, 1, 1, 2, 2, 2] into [[1, 1, 1], [2, 2, 2]]

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].

Commit Your Progress

DockYard Academy now recommends you use the latest Release rather than forking or cloning our repository.

Run git status to ensure there are no undesirable changes. Then run the following in your command line from the curriculum folder to commit your progress.

$ git add .
$ git commit -m "finish Stream Drills exercise"
$ git push

We're proud to offer our open-source curriculum free of charge for anyone to learn from at their own pace.

We also offer a paid course where you can learn from an instructor alongside a cohort of your peers. We will accept applications for the June-August 2023 cohort soon.

Navigation