In [1]:
from fpp import *

In [2]:
Just(1) | (lambda x: x + 1) | (lambda x: x * 3)


Out[2]:
<class 'fpp.Just'>(6)

In [3]:
Nothing() | (lambda x: x + 1) | (lambda x: x * 3)


Out[3]:
<class 'fpp.Nothing'>

In [4]:
Just(lambda x: x + 1) * Just(1)


Out[4]:
<class 'fpp.Just'>(2)

In [5]:
Nothing() * Just(1)


Out[5]:
<class 'fpp.Nothing'>

In [6]:
Just(1).from_maybe('return this if nothing')


Out[6]:
1

In [7]:
Nothing().from_maybe('return this if nothing')


Out[7]:
'return this if nothing'

In [8]:
Just(1).is_just()


Out[8]:
True

In [9]:
Nothing().is_nothing()


Out[9]:
True

In [10]:
Nothing().is_just()


Out[10]:
False

In [11]:
Nothing().is_nothing()


Out[11]:
True

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]:
[1, 2, 3]

In [13]:
Just(2).maybe(2, lambda x: x + 1)


Out[13]:
3

In [14]:
Nothing().maybe('default', lambda x: x + 1)


Out[14]:
'default'

In [15]:
from_maybes([Just(2), Nothing(), Just(3)])


Out[15]:
[2, 3]

In [ ]: