Created
January 26, 2010 03:25
-
-
Save colomon/286514 to your computer and use it in GitHub Desktop.
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
# .get example | |
class MapIterator does Iterator { | |
has $.base-iterator; | |
has $.code; | |
multi method get() { | |
my $value = $.base-iterator.get; | |
$value ~~ Good ?? $.code($value) !! $value; | |
} | |
} | |
# .next / .value example, .value invalid after .next returns false | |
class MapIterator does Iterator { | |
has $.base-iterator; | |
has $.code; | |
multi method next() { | |
$.base-iterator.next; | |
} | |
multi method value() { | |
$.code($.base-iterator); | |
} | |
} | |
# .next / .value example, .value "valid" after .next returns false | |
class MapIterator does Iterator { | |
has $.base-iterator; | |
has $.code; | |
has $.current; | |
multi method next() { | |
my $okay = $.base-iterator.next; | |
if ($okay) { | |
$.current = $.code($.base_iterator.value); | |
} | |
else { | |
$.current = $.base_iterator.value; | |
} | |
} | |
multi method value() { | |
$.current; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment