Skip to content

Instantly share code, notes, and snippets.

@smls
Last active August 29, 2015 14:22
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 smls/9f11b70574f7088c5922 to your computer and use it in GitHub Desktop.
Save smls/9f11b70574f7088c5922 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl6
use v6;
sub infix:<joins> ($a,$b) {
$a.substr(*-1,1) eq $b.substr(0,1) ?? "$a $b" !! Empty;
}
say <the that a> Xjoins
<elephant thing> Xjoins
<walked treaded grows> Xjoins
<slowly quickly>;
#!/usr/bin/env perl6
use v6;
sub infix:<lf> ($a,$b) {
next unless try $a.substr(*-1,1) eq $b.substr(0,1);
"$a $b";
}
multi dethunk(Callable $x) { try take $x() }
multi dethunk( Any $x) { take $x }
sub amb (*@c) { gather @c».&dethunk }
say first *, do
amb(<the that a>, { }) Xlf
amb(<frog elephant thing>) Xlf
amb(<walked treaded grows>) Xlf
amb(<slowly quickly>, { });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment