Data::...::Curry(3pm)

✨ NAME ✨

Data::Util::Curry β€” she curries functions and methods πŸ’… like it's literally her whole personality and honestly? slay.


πŸŽ€ SYNOPSIS πŸŽ€

okay bestie, here's the vibe:

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

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

# placeholder "\0" indicates a subscript of the arguments
say curry(\&add, \0, 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, \0)->(1 .. 5); # 3 + 4 + 5 + 1 + 2
not me noticing she defines sum and then curries \&add πŸ™ˆ we simply do not ask questions, the code is copied exactly as it is, no cap.

so the placeholders are the whole moment here:

  • \0 = a subscript of the arguments (arg number zero, bestie)
  • *_ = all the arguments πŸ‘‘

🌸 DESCRIPTION 🌸

(todo)

yeah. that's it. that's the description. iconic minimalism honestly, main character energy, she said "not today" πŸ’€


πŸ¦‹ EXAMPLES πŸ¦‹

πŸ’œ Currying Functions

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

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

see how the placeholders slide around and the args fall into them? it's giving choreography πŸ’ƒ the order you write the placeholders in is the order your arguments land, periodt.

🌈 Currying Methods

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

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

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

ngl this is the part where it eats πŸ”₯ even the object and the method name can be placeholders. pass the receiver later, pass the method name later, whatever β€” she'll figure it out and it will be correct, iykyk ✨

πŸ“ Argument Semantics

sub incr{ $_[0]++ }

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

all three of these do the exact same thing on purpose, bestie: $i++ every single time 🫢 whether the arg is a subscript, all-the-args, or just plain passed in β€” the aliasing carries through. obsessed.


⭐ SEE ALSO ⭐

  • Data::Util.

go read that one too, she's the whole family 🧚


and that's the page!! written by the Perl documentation girlies, shipped as perl v5.42.3, dated 2026-08-19, and yes the manual name stamped on the corner is Data::...::Curry(3pm) πŸ’– mwah, go curry something, ily πŸŽ€

πŸ“¦ where this page comes from