Created
June 1, 2023 04:55
-
-
Save librasteve/d9bf0396643d7276f2d697a8c7076ce3 to your computer and use it in GitHub Desktop.
Numeric Delegation Issue Resolved
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
#2023.05 | |
role DataSlice does Positional does Iterable { | |
has Any @.data; | |
# Positional role support | |
# viz. https://docs.raku.org/type/Positional | |
method of { | |
Any | |
} | |
method elems { | |
@!data.elems | |
} | |
method AT-POS( $p ) { | |
@!data[$p] | |
} | |
method EXISTS-POS( $p ) { | |
0 <= $p < @!data.elems ?? True !! False | |
} | |
# Iterable role support | |
# viz. https://docs.raku.org/type/Iterable | |
method iterator { | |
@!data.iterator | |
} | |
method flat { | |
@!data.flat | |
} | |
method lazy { | |
@!data.lazy | |
} | |
method hyper { | |
@!data.hyper | |
} | |
# Extra support for reduce via list and Numeric | |
#[ | |
method Numeric { | |
@!data.Numeric | |
} | |
#] | |
#[ | |
method list { | |
@!data.list | |
} | |
#] | |
} | |
my \dss = DataSlice.new( data => [1, 3, 5, 42, 6, 8] ); | |
say ~dss; | |
say [+] dss.data; #65 | |
say [+] dss; #65 | |
say dss.data + 1; #7 | |
say dss + 1; #7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment