Skip to content

Instantly share code, notes, and snippets.

@ab5tract
Created Oct 17, 2019
Embed
What would you like to do?
commit 480b4571c09d832fc5dbe63d77b4df33a7c2d1c0
Author: ab5tract <john.haltiwanger@gmail.com>
Date: Thu Oct 17 17:46:33 2019 +0200
Add single-arg target to infix:<+>
diff --git a/pimbook/secret/lib/Secret.pm6 b/pimbook/secret/lib/Secret.pm6
index 379cfc6..eaceba7 100644
--- a/pimbook/secret/lib/Secret.pm6
+++ b/pimbook/secret/lib/Secret.pm6
@@ -33,15 +33,9 @@ module Secret {
# XXX: I admit, this is cryptic :( ... maybe we can include smiley face variants?
sub interpolate(**@points) is export {
- my $p = Polynomial.new: [0];
- my @f = @points.keys.map: -> $i {
- $p += single-term @points, $i;
+ [+] @points.keys.map: -> $i {
+ single-term @points, $i
}
- $p + Polynomial.new([])
- # Bullshit that this doesn't work...
- # [+] @points.keys.map: -> $i {
- # single-term @points, $i;
- # })
}
sub single-term(@points, $i) {
@@ -90,6 +84,7 @@ module Secret {
}
}
+ multi sub infix:<+> (Polynomial:D $f) { $f }
multi sub infix:<+> (Polynomial $f, Polynomial $g, @z = zip(right-pad($f.coefficients, $g.coefficients))) is export {
Polynomial.new: @z.map(*.sum)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment