Changeset 26

Show
Ignore:
Timestamp:
10/12/08 14:44:00 (2 years ago)
Author:
Jonathan Jacobs <korpse@…>
Message:

Some utility functions.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • procyon/util.py

    r13 r26  
    107107        yield delim 
    108108        yield x 
     109 
     110 
     111def maybe(value, f, default=None): 
     112    """ 
     113    Maybe apply C{f} to C{value} otherwise return C{default}. 
     114 
     115    If C{value} is None then C{default} is returned, otherwise C{f} is applied 
     116    to C{value} and the result returned. 
     117 
     118    @type f: C{callable} 
     119    @param f: A callable that is passed one argument, C{value}, the result of 
     120        which is then returned 
     121    """ 
     122    if value is None: 
     123        return default 
     124    return f(value) 
     125 
     126