Skip to content

Instantly share code, notes, and snippets.

@AlexDaniel

AlexDaniel/&[.p6 Secret

Created September 3, 2019 02:37
Show Gist options
  • Save AlexDaniel/f3ed89d252918c3a6de67eb9ec608de2 to your computer and use it in GitHub Desktop.
Save AlexDaniel/f3ed89d252918c3a6de67eb9ec608de2 to your computer and use it in GitHub Desktop.
Language/numerics.pod6
461:say unique :with(&[==]), 1, 1, 1, 42, <42>; # OUTPUT: «(1 42)␤»
Language/rb-nutshell.pod6
1045:&[+](5, 3) # => 8, Perl 6, reference to infix addition operator
1046:&[+].^candidates # Perl 6, lists all signatures for the + operator
Language/haskell-to-p6.pod6
484: say (1..5).reduce: &[<]; # True
Type/Any.pod6
848: ("1", 1, "1 ", 2).unique( as => Int, with => &[==] ).say; #OUTPUT: «(1 2)␤»
866: <1 -1 2 -2 3>.repeated(:as(&abs),:with(&[==])).say; # OUTPUT: «(-1 -2)␤»
878: multi method squish( :&as!, :&with = &[===] )
879: multi method squish( :&with = &[===] )
889:(3+2i,3+3i,4+0i).squish( as => *.re, with => &[==]).put; #OUTPUT: «3+2i 4+0i␤»
1030: (1..13).reduce( &[*] ).say; # OUTPUT: «6227020800␤»
1044:<10 5 3>.reduce( &[*] ).say ; # OUTPUT: «150␤»
1045:<10 5 3>.produce( &[*] ).say; # OUTPUT: «(10 50 150)␤»
Type/List.pod6
868:C<(VAL1, VAL2, VAL3).reduce(&[OP])> is the same as C<VAL1 OP VAL2 OP VAL3> even
872: [2,3,4].reduce(&[**]).lsb.say; # OUTPUT: «81␤»
877: [2,3,4].reduce(&[-]).say; # OUTPUT: «-5␤»
888: say reduce &[+], @numbers; # operator does not need explicit identity
937:C<(VAL1, VAL2, VAL3).produce(&[OP])> is the same as C<VAL1 OP VAL2 OP VAL3> even
941: [2,3,4].produce(&[**]).say; # OUTPUT: «(4 81 2417851639229258349412352)␤»
942: say produce &[**], (2,3,4); # OUTPUT: «(4 81 2417851639229258349412352)␤»
946: [2,3,4].produce(&[-]).say; # OUTPUT: «(2 -1 -5)␤»
947: say produce &[-], (2,3,4); # OUTPUT: «(2 -1 -5)␤»
957: say produce &[+], @numbers; # operator does not need explicit identity
Type/Supply.pod6
749: method zip(Supply @*supplies, :&with = &[,] --> Supply:D)
759: method zip-latest(Supply @*supplies, :&with = &[,], :$initial --> Supply:D)
Type/Test.pod6
399: cmp-ok <a b c>, &[!eqv], <b d e>, 'not equal';
Type/independent-routines.pod6
979: say @list.unique(:with(&[eqv])) # OUTPUT: «({a => 42} {b => 13})␤»
1004: say @list.repeated(:with(&[eqv])) # OUTPUT: «({a => 42})␤»
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment