Skip to content

Note

This module requires optional dependencies. You can install them together with pfun using pip install pfun[test]

pfun.hypothesis_strategies.unaries(return_strategy)

Create a search strategy that produces functions of 1 argument

Examples:

>>> f = unaries(integers()).example()
>>> f
<function ...>
>>> f(None)
2

Parameters:

Name Type Description Default
return_strategy hypothesis.strategies.SearchStrategy[~A]

strategy used to draw return values

required

Returns:

Type Description
hypothesis.strategies.SearchStrategy[Callable[[object], ~A]]

Search strategy that produces callables of 1 argument

pfun.hypothesis_strategies.maybes(value_strategy)

Create a search strategy that produces pfun.maybe.Maybe values

Examples:

>>> maybes(integers()).example()
Just(1)

Parameters:

Name Type Description Default
value_strategy hypothesis.strategies.SearchStrategy[~A]

search strategy to draw values from

required

Returns:

Type Description
hypothesis.strategies.SearchStrategy[Union[pfun.maybe.Nothing, pfun.maybe.Just[~A]]]

search strategy that produces pfun.maybe.Maybe values

pfun.hypothesis_strategies.rights(value_strategy)

Create a search strategy that produces pfun.either.Right values

Parameters:

Name Type Description Default
value_strategy hypothesis.strategies.SearchStrategy[~A]

search strategy to draw values from

required

Examples:

>>> rights(integers()).example()
Right(0)

Returns:

Type Description
hypothesis.strategies.SearchStrategy[pfun.either.Right[~A]]

search strategy that produces pfun.either.Right values

pfun.hypothesis_strategies.lefts(value_strategy)

Create a search strategy that produces pfun.either.Left values

Parameters:

Name Type Description Default
value_strategy hypothesis.strategies.SearchStrategy[~A]

search strategy to draw values from

required

Examples:

>>> lefts(integers()).example()
Left(0)

Returns:

Type Description
hypothesis.strategies.SearchStrategy[pfun.either.Left[~A]]

search strategy that produces pfun.either.Left values

pfun.hypothesis_strategies.eithers(value_strategy)

Create a search strategy that produces pfun.either.Either values

Parameters:

Name Type Description Default
value_strategy hypothesis.strategies.SearchStrategy[~A]

search strategy to draw values from

required

Examples:

>>> s = eithers(integers())
>>> s.example()
Right(0)
>>> s.example()
Left(0)

Returns:

Type Description
hypothesis.strategies.SearchStrategy[Union[pfun.either.Left[~A], pfun.either.Right[~A]]]

search strategy that produces pfun.either.Either values

pfun.hypothesis_strategies.nullaries(return_strategy)

Create a search strategy that produces functions of 0 arguments

Parameters:

Name Type Description Default
return_strategy hypothesis.strategies.SearchStrategy[~A]

strategy used to draw return values

required

Examples:

>>> f = unaries(integers()).example()
>>> f
<function ...>
>>> f()
2

Returns:

Type Description
hypothesis.strategies.SearchStrategy[Callable[[], ~A]]

Search strategy that produces callables of 0 arguments

pfun.hypothesis_strategies.trampolines(value_strategy)

Create a strategy that produces pfun.trampoline.Trampoline instances

Parameters:

Name Type Description Default
value_strategy hypothesis.strategies.SearchStrategy[~A]

strategy used to draw result values

required

Examples:

>>> trampolines(integers()).example()
Call(thunk=<function ... at 0x1083d2d40>)

Returns:

Type Description
hypothesis.strategies.SearchStrategy[pfun.trampoline.Trampoline[~A]]

search strategy that produces pfun.trampoline.Trampoline instances

pfun.hypothesis_strategies.lists(elements, min_size=0)

Create a search strategy that produces pfun.list.List instances

Parameters:

Name Type Description Default
elements hypothesis.strategies.SearchStrategy[~A]

strategy used to draw elements of the list

required
min_size

minimum size of the lists

0

Examples:

>>> lists(integers()).example()
List((0,))

Returns:

Type Description

search strategy that produces pfun.list.List instances

pfun.hypothesis_strategies.dicts(keys, values, min_size=0, max_size=None)

Create a search strategy that produces pfun.dict.Dict instances

Parameters:

Name Type Description Default
keys hypothesis.strategies.SearchStrategy[~A]

search strategy used to draw keys for the Dict instances

required
values hypothesis.strategies.SearchStrategy[~B]

search strategy used to draw values for the Dict instances

required
min_size int

minimum size of the Dicts

0
max_size int

max size of the Dicts

None

Examples:

>>> dicts(text(), integers()).example()
Dict({'0': 0})

Returns:

Type Description
hypothesis.strategies.SearchStrategy[pfun.dict.Dict[~A, ~B]]

search strategy that produces pfun.dict.Dict instances

pfun.hypothesis_strategies.effects(value_strategy, include_errors=False, max_size=10, max_leaves=10)

Create a search strategy that produces pfun.effect.Effect instances

Parameters:

Name Type Description Default
value_strategy hypothesis.strategies.SearchStrategy[~A]

search strategy used to draw success values

required
include_errors bool

whether to include effects that fail

False
max_size int

max size of effects that produces iterables (such as pfun.effect.gather)

10
max_leaves int

max number of leaf effects (pfun.effect.success, pfun.effect.from_callable etc) to be drawn

10

Examples:

>>> e = effects(integers()).example()
>>> e
success(0)
>>> e.run(None)
0

Returns:

Type Description
hypothesis.strategies.SearchStrategy[pfun.effect.Effect[object, Any, ~A]]

search strategy that produces pfun.effect.Effect instances