(1..10).map( *²).say;
(1..10).map( *²).grep( * ≥ 12 ).say;
1..10 ==> map( *²) ==> grep( * ≥ 12 ) ==> my @output;
@output.join( " ⬖ ").put;
#!/usr/bin/env perl6
use v6;
((1..10) »**» 2 ).duckmap: -> $x where * ≥ 12 { $x.say };
=output
16
25
....
sub quita-no-mayúsculas( Str $cadena ‐‐> Seq ) {
return $cadena.comb.grep: * ∉ 'A'..'Z';
}
say quita-no-mayúsculas( "LaTeX" );
say quita-no-mayúsculas( "Learn You a Perl 6" );
say &quita-no-mayúsculas.^name # Sub+{Callable[Seq]}
sub þor( Int, Int ‐‐> Str ) {};
say &þor.^name; # Sub+{Callable[Str]}
say &þor.^mro;
#((Sub+{Callable[Str]}) (Sub) (Routine) (Block) (Code) (Any) (Mu))
role CasiEq {
method casi-igual( \rhs ‐‐> Bool) {...}
method casi-diferente( \rhs ‐‐> Bool) {...}
}
class CasiEqInt does CasiEq {
has Int $.n;
method casi-igual ( \rhs ‐‐> Bool) { return True if abs($!n - rhs) ≤ 1 }
method casi-diferente ( \rhs ‐‐> Bool) { True unless abs($!n - rhs) ≤ 1}
method Numeric( ‐‐> Numeric:D ) { return $!n }
}
my $n1 := CasiEqInt.new( n => 1 );
my $n2 := CasiEqInt.new( n => 2 );
say "Casi " if $n1.casi-igual($n2);
proto sub infix:<≈> ( | ‐‐> Bool) {*}
multi sub infix:<≈> ( Int $lhs, Int $rhs ‐‐> Bool) {
return True if abs( $lhs - $rhs) ≤ 1
}
say "Casi " if 3 ≈ 2 ;
proto sub lucky (Int \a ‐‐> Str ) { *}
multi sub lucky ( 7 ) { "LUCKY NUMBER SEVEN!" }
multi sub lucky ( $x where * ≠ 7 ) { "Sorry, you're out of luck, pal!" };
say lucky 7 ;
say lucky 33;
sub mult-three( \a, \b, \c ) {
return a * b * c;
}
my &mult-two-with-nine = &mult-three.assuming( *, *, 9);
say mult-two-with-nine 2, 3;
sub apply-twice( &f, \a ) { f( f ( a ) ) }
say apply-twice( * + 3, 10 );
say apply-twice( * ~ " HAHA" , "HEY" );
say apply-twice( "HAHA " ~ *, "HEY" );
say ((1..5) Z (5...1)).map( -> (\a, \b) { (a*30+3)/b });
say map( { ( { - $_ } ∘ &abs)($_) }, [5,-3,-6,7,-3,2,-19,24])
class Just {
has &.a;
method new( $a ) {
return self.bless( a => {$a} );
}
method CALL-ME( |c ) {
return &!a();
}
}
multi sub maybe( &f, Nil ) { return Nil };
multi sub maybe( &f, Just $x ) { return Just.new( f( $x() ) ) };
my $treinta-y-tres = Just.new( -33 );
say maybe &abs, Nil;
say (maybe &abs, $treinta-y-tres )();
# fmap (++ " HEY GUYS IM INSIDE THE JUST") (Just "Something serious.")
multi sub fmap( &f, Nil ) { return Nil };
multi sub fmap( &f, Just $x ) { return Just.new( f( $x() ) ) ;}
say fmap * ~ " HEY GUYS IM INSIDE THE JUST", Just.new: "Something serious.";
{
say "Write a couple of lines here ->";
my $line_from_user = getLine();
my $echo = mbind($line_from_user, -> $x { putStrLn($x) });
my @actions = (getLine(), $echo);
my $both = sequence_(@actions);
$both();
}
jj.github.io/fp-perl6/eslibre.html
git.io/p6lambda