View Restricted.rakumod
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
use uniname-words; | |
constant $stdin-text = qq:to/EOH/; | |
I ♥ Raku! | |
1 22 333 4444 55555 6565656 | |
3.14159265358979323846264338327950288419716939937510582097494459 | |
A line with the number 42. | |
We may need some "quotes". | |
A backslash \\ | |
would be nice too. |
View Restricted.rakumod
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
use uniname-words; | |
constant $stdin-text = qq:to/EOH/; | |
I ♥ Raku! | |
1 22 333 4444 55555 6565656 | |
3.14159265358979323846264338327950288419716939937510582097494459 | |
A line with the number 42. | |
We may need some "quotes". | |
A backslash \\ | |
would be nice too. |
View gist:c69612be47e078d090467bf3972fc3f2
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
sub limit-rate(Supply $in, $per-seconds = 1 --> Supply:D) { | |
my $out = Supplier::Preserving.new; | |
start react whenever $in -> \value { | |
$out.emit: value; | |
sleep(1 / $per-seconds); | |
} | |
$out.Supply; | |
} |
View keymap.raku
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
use v6.d; | |
constant @keymap = (0x1b, 0x5b, 0x31, 0x31, 0x7e) => 'F1', (0x61,) => 'a', (0x0a,) => 'ENTER'; | |
use Term::ReadKey; | |
react { | |
whenever key-pressed( :!echo ) { | |
state @stack; | |
@stack.push: .ord; | |
# .ord.fmt('%02x').put; # uncomment to discover new keycodes |
View nncal.raku
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
multi sub MAIN(Bool :$S, Bool :$three) { | |
constant @months = <January February March April May June July August September October November December>; | |
my @week-days = $S ?? <Su Mo Tu We Th Fr Sa> !! <Mo Tu We Th Fr Sa Su>; | |
my &start-week-day = $S ?? { .[0].day-of-week % 7 } !! { .[0].day-of-week - 1 } | |
my $month-offset = $three ?? -1 !! 0; | |
loop { | |
$_ = now.Date.truncated-to('month'); | |
$_ = .earlier(:month(1)) if $three; |
View foo.txt
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
ub exclude(@a, $elems) { | |
say (0..^$elems).grep: * !~~ @a | |
} | |
my @a = 1..10; | |
@a[&exclude.assuming(2..3)].say; | |
View Restricted.rakumod
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
use uniname-words; | |
constant $stdin-text = qq:to/EOH/; | |
I ♥ Raku! | |
1 22 333 4444 55555 6565656 | |
3.14159265358979323846264338327950288419716939937510582097494459 | |
A line with the number 42. | |
We may need some "quotes". | |
A backslash \\ | |
would be nice too. |
View coerce-subsets.raku
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
use v6.*; | |
class Type is Int { } | |
subset Even of Type where * %% 2; | |
Type.^add_method('COERCE', my method COERCE(|) { | |
my Even $retval = 42 | |
}); | |
sub foo(Even() $_) { .&dd } | |
foo ‘answer’; |
View spinner.raku
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
use v6.d; | |
# my @loop = |("\x1F550" .. "\x1F55B") xx *; | |
# react whenever Supply.interval(0.1) { | |
# state $it = @loop.iterator; | |
# print "\b\b" ~ $it.pull-one; | |
# } | |
sub progress-bar($max, $width = 10) { |
View did-you-know.raku
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
# Did you know, you can use the method `.none` (and friends) of `Any` in a method call chain? | |
my \fib = 1, 1, * + * … ∞; | |
say so fib[^10].none.is-prime; | |
say so fib[^10].any.is-prime; | |
say so fib[5..9].one.is-prime; | |
# A `Junction` is a parallel value that whats to collaps into a single `Bool`. Any method call to a definite `Junction` will be forwarded to its members, coerced to `Bool` and collapsed with the `Junction`-type. The above `any`-form is equivalent to: |
NewerOlder