A little present.

Harald Hanche-Olsen hanche at math.ntnu.no
Tue Feb 15 01:38:16 CET 2000

+ Michael Hudson <mwh21 at cam.ac.uk>:

| >>> from papply import X
| >>> map(X(t,(),73),range(10))
| The idea is that after a call to X(func,...) there are a number of
| `holes' (notated by an empty tuple) in the arglist that can be `filled
| in' by subsequent calls (to what X returns). This means you can't
| presupply the empty tuple to func, but I couldn't think of a better
| way.
| It's a bit like currying, but more general.

Useful, but a bit complicated methinks.  I recently cooked up this
somewhat simpler class, to solve a commonly occuring variant of your

class preapply:
    '"Apply" a function to too few args, returning a function.'
    def __init__(self, proc, *args):
	self.args = args
	self.proc = proc
	self.ignore = 0
    def ignoring(self, ignore):
        'Make this class, when called, ignore this many initial args'
	self.ignore = ignore
	return self
    def __call__(self, *args):
	apply(self.proc, self.args + args[self.ignore:])

I particularly like the option of binding preapply(f).ignoring(1) to a
Tkinter event, for all those cases when f has no need of the event
parameter itself.  (No, I am not proud of the docstrings.)

or-maybe-I-should-have-named-the-class-Schoenfinkel-ly y'rs,
* Harald Hanche-Olsen     <URL:http://www.math.ntnu.no/~hanche/>
- "There arises from a bad and unapt formation of words
   a wonderful obstruction to the mind."  - Francis Bacon

More information about the Python-list mailing list