# Pastebin XbfFizxy class Actual { has Iterator $.rest is required } class TurnOffIterator does Iterator { has Iterator $.orig; has Iterator $!actual; has $.cond = { True }; method pull-one { with $!orig { my \r = .pull-one; say "orig: ", r; return r if r =:= IterationEnd or r !~~ Actual; $!orig = Nil; $!actual = r.rest; return self.pull-one } else { my \r = $!actual.pull-one; say "actual: ", r; return r if r =:= IterationEnd; return r if r ~~ $!cond; IterationEnd but Actual.new: :rest($!actual) } } } role CondSeq { method take-while($cond) { my $iter = $.iterator; Seq.new(TurnOffIterator.new: :orig( $iter ~~ TurnOffIterator ?? $iter !! class :: does Iterator { method pull-one { Actual.new: :rest($iter) } }.new ), :$cond, :take) but CondSeq } }