<s> """<STR_LIT>""" <EOL> from ants . utils . misc import arg_to_iter <EOL> from ants . utils . datatypes import MergeDict <EOL> from . common import wrap_loader_context <EOL> class MapCompose ( object ) : <EOL> def __init__ ( self , * functions , ** default_loader_context ) : <EOL> self . functions = functions <EOL> self . default_loader_context = default_loader_context <EOL> def __call__ ( self , value , loader_context = None ) : <EOL> values = arg_to_iter ( value ) <EOL> if loader_context : <EOL> context = MergeDict ( loader_context , self . default_loader_context ) <EOL> else : <EOL> context = self . default_loader_context <EOL> wrapped_funcs = [ wrap_loader_context ( f , context ) for f in self . functions ] <EOL> for func in wrapped_funcs : <EOL> next_values = [ ] <EOL> for v in values : <EOL> next_values += arg_to_iter ( func ( v ) ) <EOL> values = next_values <EOL> return values <EOL> class Compose ( object ) : <EOL> def __init__ ( self , * functions , ** default_loader_context ) : <EOL> self . functions = functions <EOL> self . stop_on_none = default_loader_context . get ( '<STR_LIT>' , True ) <EOL> self . default_loader_context = default_loader_context <EOL> def __call__ ( self , value , loader_context = None ) : <EOL> if loader_context : <EOL> context = MergeDict ( loader_context , self . default_loader_context ) <EOL> else : <EOL> context = self . default_loader_context <EOL> wrapped_funcs = [ wrap_loader_context ( f , context ) for f in self . functions ] <EOL> for func in wrapped_funcs : <EOL> if value is None and self . stop_on_none : <EOL> break <EOL> value = func ( value ) <EOL> return value <EOL> class TakeFirst ( object ) : <EOL> def __call__ ( self , values ) : <EOL> for value in values : <EOL> if value is not None and value != '<STR_LIT>' : <EOL> return value <EOL> class Identity ( object ) : <EOL> def __call__ ( self , values ) : <EOL> return values <EOL> class Join ( object ) : <EOL> def __init__ ( self , separator = u'<STR_LIT:U+0020>' ) : <EOL> self . separator = separator <EOL> def __call__ ( self , values ) : <EOL> return self . separator . join ( values ) </s>
