Skip to content

Commit

Permalink
Use Stream.zip + Enum.take to exercise Enumerable.reduce usage of :su…
Browse files Browse the repository at this point in the history
…spended.
  • Loading branch information
Qqwy committed Sep 4, 2021
1 parent 1328407 commit 5bf36d2
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 16 deletions.
3 changes: 3 additions & 0 deletions lib/arrays.ex
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ contents = quote do
iex> foods |> Enum.take(2)
["Cheese", "Strawberries"]
iex> Arrays.new([1, 2, 3]) |> Stream.zip(Arrays.new([4, 5, 6])) |> Enum.take(2)
[{1, 4}, {2, 5}]
#### Collectable
Expand Down
8 changes: 0 additions & 8 deletions test/implementations/erlang_array_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,4 @@ defmodule Implementations.ErlangArrayTest do
alias Arrays.Test.Support.Arrays.DoctestErlangArray, as: Arrays
doctest Arrays, except: [empty: 1]
end

test "Enumerable reduce suspended (ErlangArray)" do
{:suspended, 42, fun} =
Arrays.new([1, 2, 3, 4], implementation: Arrays.Implementations.ErlangArray)
|> Enumerable.reduce({:suspend, 42}, fn val, acc -> {:cont, val + acc} end)

assert {:done, 79} = fun.({:cont, 69})
end
end
8 changes: 0 additions & 8 deletions test/implementations/map_array_test.exs
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
defmodule Implementations.MapArrayTest do
use ExUnit.Case, async: true

test "Enumerable reduce suspended (MapArray)" do
{:suspended, 42, fun} =
Arrays.new([1, 2, 3, 4], implementation: Arrays.Implementations.MapArray)
|> Enumerable.reduce({:suspend, 42}, fn val, acc -> {:cont, val + acc} end)

assert {:done, 79} = fun.({:cont, 69})
end
end

0 comments on commit 5bf36d2

Please sign in to comment.