Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save librasteve/d9bf0396643d7276f2d697a8c7076ce3 to your computer and use it in GitHub Desktop.
Save librasteve/d9bf0396643d7276f2d697a8c7076ce3 to your computer and use it in GitHub Desktop.
Numeric Delegation Issue Resolved
#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