logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

curry - Create automatic curried method call closures for any class or object

Author

       mst - Matt S. Trout (cpan:MSTROUT) <mst@shadowcat.co.uk>

Contributors

       None yet - maybe this software is perfect! (ahahahahahahahahaha)

License

       This library is free software and may be distributed under the same terms as perl itself.

perl v5.36.0                                       2022-11-19                                         curry(3pm)

Name

       curry - Create automatic curried method call closures for any class or object

Rationale

       How many times have you written

         sub { $obj->something($some, $args, @_) }

       or worse still needed to weaken it and had to check and re-check your code to be sure you weren't closing
       over things the wrong way?

       Right. That's why I wrote this.

Synopsis

         use curry;

         my $code = $obj->curry::frobnicate('foo');

       is equivalent to:

         my $code = sub { $obj->frobnicate(foo => @_) };

       If you have a method name (or a coderef), you can call (as of version 2):

         my $code = $obj->curry::_($method => 'foo');

       Additionally,

         use curry::weak;

         my $code = $obj->curry::weak::frobnicate('foo');

       is equivalent to:

         my $code = do {
           Scalar::Util::weaken(my $weak_obj = $obj);
           sub {
             return unless $weak_obj; # in case it already went away
             $weak_obj->frobnicate(foo => @_)
           };
         };

       Similarly, given a method name or coderef (as of version 2):

         my $code = $obj->curry::weak::_($method => 'foo');

       There are also $curry::curry and $curry::weak globals that work equivalently to "curry::_" and
       "curry::weak::_" respectively - you'll quite possibly see them in existing code because they were
       provided in pre-2.0 versions but they're unlikely to be the best option for new code.

See Also