Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test() -> Maybe[int]:
return Just(1)
def _test_just_inequality(self, value):
assert Just(value) != Nothing()
def _test_nothing_inequality(self, first, second):
assume(first != second)
assert Just(first) != Just(second)
def test_composition_law(self, f: Unary, g: Unary, value):
h = compose(f, g)
assert Just(value).map(h) == Just(value).map(g).map(f)
assert Nothing().map(h) == Nothing().map(g).map(f)
def _test_just_equality(self, value):
assert Just(value) == Just(value)
def test_sequence(self):
assert sequence([Just(v) for v in range(3)]) == Just((0, 1, 2))
def maybes(value_strategy=anything()):
justs = builds(maybe.Just, value_strategy)
nothings = just(maybe.Nothing())
return one_of(justs, nothings)
"""
Map each element in ``iterable`` by applying ``f``,
filter the results by the value returned by ``f``
and combine from left to right.
Example:
>>> filter_m(lambda v: Just(v % 2 == 0), range(3))
Just((0, 2))
Args:
f: Function to map ``iterable`` by
iterable: Iterable to map by ``f``
Return:
`iterable` mapped and filtered by `f`
"""
return cast(Maybe[Iterable[A]], filter_m_(Just, f, iterable))
Nothing()
>> Dict({'key': 'value'}).get('key')
Just('value')
Args:
key: the key to retrieve
default: value to return if the key is not found
Return:
`Just` if key is found in dictionary
or default is given,
`Nothing` otherwise
"""
v = self._d.get(key)
if v is None:
return Nothing()
return Just(v)