GNU.WIKI: The GNU/Linux Knowledge Base

  [HOME] [PHP Manual] [HowTo] [ABS] [MAN1] [MAN2] [MAN3] [MAN4] [MAN5] [MAN6] [MAN7] [MAN8] [MAN9]

  [0-9] [Aa] [Bb] [Cc] [Dd] [Ee] [Ff] [Gg] [Hh] [Ii] [Jj] [Kk] [Ll] [Mm] [Nn] [Oo] [Pp] [Qq] [Rr] [Ss] [Tt] [Uu] [Vv] [Ww] [Xx] [Yy] [Zz]


NAME

       Data::Util::Curry - Curries functions and methods

SYNOPSIS

               use feature 'say';
               use Data::Util qw(curry);

               sub sum{
                       my $total = 0;
                       for my $x(@_){
                               $total += $x;
                       }
                       return $total;
               }

               # placeholder "" indicates a subscript of the arguments
               say curry(\&add, , 42)->(10); # 52

               # placeholder "*_" indicates all the arguments
               say curry(\&add, *_)->(1 .. 10); # 55

               # two subscripts and the rest of the arguments
               say curry(\&add, *_, , )->(1 .. 5); # 3 + 4 + 5 + 1 + 2

DESCRIPTION

       (todo)

EXAMPLES

   Currying Functions
               curry(\&f, , 2)->(1); # f(1, 2)
               curry(\&f, 3, )->(4); # f(3, 4)
               curry(\&f, *_)->(5, 6); # f(5, 6)

               curry(\&f, , , *_)->(1, 2, 3, 4); # f(1, 2, 3, 4)
               curry(\&f, *_, , )->(1, 2, 3, 4); # f(3, 4, 1, 2)

   Currying Methods
               curry($obj, 'something', *_)->(1, 2);  # $obj->something(1, 2)

               curry($obj, 'something',
                       foo => ,
                       bar => )->(1, 2); # $obj->something(foo => 1, bar => 2)

               curry(, 'something', )->($obj, 42);   # $obj->something(42)
               curry($obj, , *_)->('something', 1, 2); # $obj->something(1, 2)

   Argument Semantics
               sub incr{ $_[0]++ }

               my $i = 0;
               curry(\&incr, )->($i); # $i++
               curry(\&incr, *_)->($i); # $i++
               curry(\&incr, $i)->();   # $i++

SEE ALSO

       Data::Util.



  All copyrights belong to their respective owners. Other content (c) 2014-2018, GNU.WIKI. Please report site errors to webmaster@gnu.wiki.
Page load time: 0.122 seconds. Last modified: November 04 2018 12:49:43.