<s> import collections <EOL> from . lists import unique <EOL> class Result ( object ) : <EOL> def __init__ ( self , value , messages ) : <EOL> self . value = value <EOL> self . messages = unique ( messages ) <EOL> def map ( self , func ) : <EOL> return Result ( func ( self . value ) , self . messages ) <EOL> def bind ( self , func ) : <EOL> result = func ( self . value ) <EOL> return Result ( result . value , self . messages + result . messages ) <EOL> Message = collections . namedtuple ( "<STR_LIT>" , [ "<STR_LIT:type>" , "<STR_LIT:message>" ] ) <EOL> def warning ( message ) : <EOL> return Message ( "<STR_LIT>" , message ) <EOL> def success ( value ) : <EOL> return Result ( value , [ ] ) <EOL> def combine ( results ) : <EOL> values = [ ] <EOL> messages = [ ] <EOL> for result in results : <EOL> values . append ( result . value ) <EOL> for message in result . messages : <EOL> messages . append ( message ) <EOL> return Result ( values , messages ) <EOL> def map ( func , * args ) : <EOL> return combine ( args ) . map ( lambda values : func ( * values ) ) </s>
