.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Data::Util::Curry 3pm" .TH Data::Util::Curry 3pm 2024-03-07 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Data::Util::Curry \- Curries functions and methods .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 2 \& use feature \*(Aqsay\*(Aq; \& use Data::Util qw(curry); \& \& sub sum{ \& my $total = 0; \& for my $x(@_){ \& $total += $x; \& } \& return $total; \& } \& \& # placeholder "\e0" indicates a subscript of the arguments \& say curry(\e&add, \e0, 42)\->(10); # 52 \& \& # placeholder "*_" indicates all the arguments \& say curry(\e&add, *_)\->(1 .. 10); # 55 \& \& # two subscripts and the rest of the arguments \& say curry(\e&add, *_, \e1, \e0)\->(1 .. 5); # 3 + 4 + 5 + 1 + 2 .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" (todo) .SH EXAMPLES .IX Header "EXAMPLES" .SS "Currying Functions" .IX Subsection "Currying Functions" .Vb 3 \& curry(\e&f, \e0, 2)\->(1); # f(1, 2) \& curry(\e&f, 3, \e0)\->(4); # f(3, 4) \& curry(\e&f, *_)\->(5, 6); # f(5, 6) \& \& curry(\e&f, \e0, \e1, *_)\->(1, 2, 3, 4); # f(1, 2, 3, 4) \& curry(\e&f, *_, \e0, \e1)\->(1, 2, 3, 4); # f(3, 4, 1, 2) .Ve .SS "Currying Methods" .IX Subsection "Currying Methods" .Vb 1 \& curry($obj, \*(Aqsomething\*(Aq, *_)\->(1, 2); # $obj\->something(1, 2) \& \& curry($obj, \*(Aqsomething\*(Aq, \& foo => \e0, \& bar => \e1)\->(1, 2); # $obj\->something(foo => 1, bar => 2) \& \& curry(\e0, \*(Aqsomething\*(Aq, \e1)\->($obj, 42); # $obj\->something(42) \& curry($obj, \e0, *_)\->(\*(Aqsomething\*(Aq, 1, 2); # $obj\->something(1, 2) .Ve .SS "Argument Semantics" .IX Subsection "Argument Semantics" .Vb 1 \& sub incr{ $_[0]++ } \& \& my $i = 0; \& curry(\e&incr, \e0)\->($i); # $i++ \& curry(\e&incr, *_)\->($i); # $i++ \& curry(\e&incr, $i)\->(); # $i++ .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" Data::Util.