In [1]:
from fpp import *
In [2]:
Just(1) | (lambda x: x + 1) | (lambda x: x * 3)
Out[2]:
In [3]:
Nothing() | (lambda x: x + 1) | (lambda x: x * 3)
Out[3]:
In [4]:
Just(lambda x: x + 1) * Just(1)
Out[4]:
In [5]:
Nothing() * Just(1)
Out[5]:
In [6]:
Just(1).from_maybe('return this if nothing')
Out[6]:
In [7]:
Nothing().from_maybe('return this if nothing')
Out[7]:
In [8]:
Just(1).is_just()
Out[8]:
In [9]:
Nothing().is_nothing()
Out[9]:
In [10]:
Nothing().is_just()
Out[10]:
In [11]:
Nothing().is_nothing()
Out[11]:
In [12]:
def greater_then_zero(v):
if v > 0:
return Just(v)
else:
return Nothing()
map_maybes(greater_then_zero, [1,2,-1,3])
Out[12]:
In [13]:
Just(2).maybe(2, lambda x: x + 1)
Out[13]:
In [14]:
Nothing().maybe('default', lambda x: x + 1)
Out[14]:
In [15]:
from_maybes([Just(2), Nothing(), Just(3)])
Out[15]:
In [ ]: