No such thing as a small change | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
I'm not a huge user of it, but I think you can look at currying a multi-arg function as quite similar to constructing an object from a factory.
In both cases, you don't need to do it. Instead of creating the object, you could pass around all the parameters needed to construct the object everywhere you'd pass the object instead. Both approaches "bundle" a bunch of information into a single context which can operate on things and be handily passed around. Another way of looking at is both approaches allow you to make a specific tool (tailored object from factory or curried function) from a general one (factory or multi-arg function). It's also very useful in 'map' or 'filter' (i.e. grep in perl), like situations, where you want a single-arg function to run the map or filter. e.g. It's still a bit contrived, but I hope you can see the idea. In a more functional language 'grep' is written as 'filter' and would generally take a one-arg function as it's first argument. In reply to Re: Currying--useful examples?
by jbert
|
|