@@ -106,7 +106,7 @@ defmodule Stream do
106
106
107
107
def member? ( Lazy [ ] = lazy , value ) do
108
108
do_reduce ( lazy , false , fn ( entry , _ ) ->
109
- if entry === value , do: throw ( { :stream_lazy , true } ) , else: false
109
+ if entry === value , do: throw ( { :stream_lazy , 0 , true } ) , else: false
110
110
end , 0 )
111
111
end
112
112
@@ -115,13 +115,13 @@ defmodule Stream do
115
115
end
116
116
117
117
defp do_reduce ( Lazy [ enumerable : enumerable , fun: f1 , acc: side ] , acc , fun , nesting ) do
118
- do_reduce ( enumerable , { acc , side } , f1 . ( fun ) , nesting + 1 )
118
+ do_reduce ( enumerable , { acc , side } , f1 . ( fun , nesting ) , nesting + 1 )
119
119
end
120
120
121
121
defp do_reduce ( enumerable , acc , fun , nesting ) do
122
122
Enumerable . reduce ( enumerable , acc , fun ) |> remove_nesting ( nesting )
123
123
catch
124
- { :stream_lazy , res } -> res
124
+ { :stream_lazy , nesting , res } -> remove_nesting ( res , nesting )
125
125
end
126
126
127
127
defp remove_nesting ( acc , 0 ) , do: acc
@@ -208,7 +208,7 @@ defmodule Stream do
208
208
@ spec drop ( Enumerable . t , non_neg_integer ) :: t
209
209
def drop ( enumerable , n ) when n >= 0 do
210
210
Lazy [ enumerable : enumerable ,
211
- fun: fn ( f1 ) ->
211
+ fun: fn ( f1 , _ ) ->
212
212
fn
213
213
_entry , { acc , n } when n > 0 ->
214
214
{ acc , n - 1 }
@@ -233,7 +233,7 @@ defmodule Stream do
233
233
@ spec drop_while ( Enumerable . t , ( element -> as_boolean ( term ) ) ) :: t
234
234
def drop_while ( enumerable , f ) do
235
235
Lazy [ enumerable : enumerable ,
236
- fun: fn ( f1 ) ->
236
+ fun: fn ( f1 , _ ) ->
237
237
fn
238
238
entry , { acc , true } ->
239
239
if f . ( entry ) , do: { acc , true } , else: { f1 . ( entry , acc ) , false }
@@ -392,10 +392,10 @@ defmodule Stream do
392
392
393
393
def take ( enumerable , n ) when n > 0 do
394
394
Lazy [ enumerable : enumerable ,
395
- fun: fn ( f1 ) ->
395
+ fun: fn ( f1 , nesting ) ->
396
396
fn ( entry , { acc , n } ) ->
397
397
res = f1 . ( entry , acc )
398
- if n > 1 , do: { res , n - 1 } , else: throw { :stream_lazy , res }
398
+ if n > 1 , do: { res , n - 1 } , else: throw { :stream_lazy , nesting , res }
399
399
end
400
400
end ,
401
401
acc: n ]
@@ -415,12 +415,12 @@ defmodule Stream do
415
415
@ spec take_while ( Enumerable . t , ( element -> as_boolean ( term ) ) ) :: t
416
416
def take_while ( enumerable , f ) do
417
417
Lazy [ enumerable : enumerable ,
418
- fun: fn ( f1 ) ->
418
+ fun: fn ( f1 , nesting ) ->
419
419
fn ( entry , { acc , true } ) ->
420
420
if f . ( entry ) do
421
421
{ f1 . ( entry , acc ) , true }
422
422
else
423
- throw { :stream_lazy , acc }
423
+ throw { :stream_lazy , nesting , acc }
424
424
end
425
425
end
426
426
end ,
@@ -441,10 +441,10 @@ defmodule Stream do
441
441
@ spec with_index ( Enumerable . t ) :: t
442
442
def with_index ( enumerable ) do
443
443
Lazy [ enumerable : enumerable ,
444
- fun: fn ( f1 ) ->
444
+ fun: fn ( f1 , _ ) ->
445
445
fn ( entry , { acc , counter } ) ->
446
446
acc = f1 . ( { entry , counter } , acc )
447
- { acc , counter + 1 }
447
+ { acc , counter + 1 }
448
448
end
449
449
end ,
450
450
acc: 0 ]
0 commit comments