-
Notifications
You must be signed in to change notification settings - Fork 600
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c9db06a
commit bbf3d20
Showing
3 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
defmodule Streams do | ||
use Koans | ||
|
||
@intro "Streams" | ||
|
||
koan "Streams are lazier than Enum, they only return a struct" do | ||
assert Stream.map([1, 2, 3], &(&1 + 1)).__struct__ == ___ | ||
end | ||
|
||
koan "You have to ask it explicitly to do the operation" do | ||
updated_list = | ||
[1, 2, 3] | ||
|> Stream.map(&(&1 + 1)) | ||
|> Enum.to_list | ||
|
||
assert updated_list == ___ | ||
end | ||
|
||
koan "Which will let you decide which element you want to compute in the stream" do | ||
computed_element = | ||
1..42 | ||
|> Stream.map(&("I computed: #{&1}")) | ||
|> Enum.take(1) | ||
|
||
assert computed_element == ___ | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
defmodule StreamsTests do | ||
use ExUnit.Case | ||
import TestHarness | ||
|
||
test "Streams" do | ||
answers = [ | ||
Stream, | ||
[2, 3, 4], | ||
["I computed: 1"], | ||
] | ||
|
||
test_all(Streams, answers) | ||
end | ||
end |