pytoolz/toolz — pull request #144 by eriknw (2014-03-17 17:42:30+00:00)
Title: Memoize unary

Memoization key for unary function (single arg input only) is the arg.

In other words, for a function `f(x)`, the key would be `x`, not `(x,)`, thus saving memory and providing a more user-friendly cache. The function, of course, must be able to be interpreted by `inspect.getargspec`, or else the default key `(args, frozenset(kwargs.items()))` is used.

I recently tried to supply an initial cache to a unary function, but I didn't provide the keys as tuples, so it didn't work. Consider providing the initial terms to a Fibonacci function. Originally, this would be:
```python
@curry(memoize, cache={(0,): 0, (1,): 1})
def fib(n):
return fib(n - 1) + fib(n - 2)
```
This is prone to error.

With the current PR, the above would be:
```python
@curry(memoize, cache={0: 0, 1: 1})
def fib(n):
return fib(n - 1) + fib(n - 2)
```
I think this is much more intuitive.

Side thought: what do you think of `memoize` accepting a `key` function such that users can provide a function `key(args, kwargs)` to calculate the key for the cache?