This Raku expression converts color codes from RGB to HEX:
raku -e 'my @array = (0, 255, 0), { @^a «+» (25.5, -25.5, 0) } ... ( * ~~ (255, 0, 0 ) );
say @array.map: "#" ~ *.fmt: "%02X"'
(#00 FF 00 #19 E5 00 #33 CC 00 #4C B2 00 #66 99 00 #7F 7F 00 #99 66 00 #B2 4C 00 #CC 33 00 #E5 19 00 #FF 00 00)
Adding q{} to the expression removes spaces:
raku -e 'my @array = (0, 255, 0), { @^a «+» (25.5, -25.5, 0) } ... ( * ~~ (255, 0, 0 ) );
say @array.map: "#" ~ *.fmt: "%02X", q{}'
(#00FF00 #19E500 #33CC00 #4CB200 #669900 #7F7F00 #996600 #B24C00 #CC3300 #E51900 #FF0000)
I have not been able to figure out why adding 'q{}' to the expression removes spaces. I would aprreciate any hint on this issue. Thanks.
Per the doc for .fmt applied to a List, the routine's signature is:
method fmt($format = '%s', $separator = ' ' --> Str:D)
▲▲▲ - default separator
So, by default, each three element List like (0, 255, 0) will turn into three formatted elements separated by a space when you don't specify the separator, but unseparated when you specify a null string as the specifier.
q{} is a string (using the Q lang) that specifies a null string (ie it's the same as '').
Hence the result you're seeing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With