daily pastebin goal
41%
SHARE
TWEET

[Perl 6] Laziness in iterators.

cwchen Nov 28th, 2017 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. sub filter($f, @arr) {
  2.     gather {
  3.         for @arr -> $e {
  4.             take $e if $f($e);
  5.         }
  6.     }
  7. }
  8.  
  9. my @even = filter({ $_ mod 2 == 0 }, 1..Inf)[0..4];
  10. @even ~~ (2, 4, 6, 8, 10) or die "Wrong array {@even}";
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top