How Awful is My Decorator?
<p>I recently created a @sequenceable decorator, that can be applied to any function that takes one argument, and causes it to automatically be applicable to any sequence. This is the code (Python 2.5):</p>

<pre><code>def sequenceable(func):
    def newfunc(arg):
        if hasattr(arg, '__iter__'):
            if isinstance(arg, dict):
                return dict((k, func(v)) for k, v in arg.iteritems())
            else:
                return map(func, arg)
        else:
            return func(arg)
    return newfunc
</code></pre>

<p>In use:</p>

<pre><code>@sequenceable
def unixtime(dt):
    return int(dt.strftime('%s'))

&gt;&gt;&gt; unixtime(datetime.now())
1291318284
&gt;&gt;&gt; unixtime([datetime.now(), datetime(2010, 12, 3)])
[1291318291, 1291352400]
&gt;&gt;&gt; unixtime({'start': datetime.now(), 'end': datetime(2010, 12, 3)})
{'start': 1291318301, 'end': 1291352400}
</code></pre>

<p>My questions are:</p>

<ul>
<li>Is this a terrible idea, and why?</li>
<li>Is this a possibly good idea, but has significant drawbacks as implemented?</li>
<li>What are the potential pitfalls of
using this code?</li>
<li>Is there a builtin or library that
already does what I'm doing?</li>
</ul>
