Skip to content

Commit

Permalink
Express Failure recover as a Try_ map
Browse files Browse the repository at this point in the history
  • Loading branch information
zero323 committed Nov 1, 2015
1 parent 0a3b784 commit 4842673
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions tryingsnake/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def map(self, f):
>>> Success("1").map(f)
Failure(Exception('e',))
"""
raise NotImplementedError # pragma: no cover
return Try(f, self._v)

def flatMap(self, f):
""" Apply function returning Try_ to the value.
Expand Down Expand Up @@ -245,9 +245,6 @@ def getOrElse(self, default):
def orElse(self, default):
return self

def map(self, f):
return Try(f, self._v)

def filter(self, f, exception_cls=Exception, msg=None):
return (self if f(self.get())
else Failure(exception_cls(msg if msg else repr(f))))
Expand Down Expand Up @@ -307,7 +304,7 @@ def filter(self, f, exception_cls=Exception, msg=None):
return self

def recover(self, f):
return Try(f, self._v)
return Try_.map(self, f)

def recoverWith(self, f):
return Try_.flatMap(self, f)
Expand Down

0 comments on commit 4842673

Please sign in to comment.