Skip to content
Snippets Groups Projects
Commit 576cd4ef authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

added new predicates

parent d4ead39d
No related branches found
No related tags found
No related merge requests found
......@@ -6,3 +6,9 @@ Predicates are functions that take something and return a boolean about truthful
of given statement. Satella contains a bunch of functions to produce these predicates.
.. autofunction:: satella.coding.predicates.between
.. autofunction:: satella.coding.predicates.length_is
.. autofunction:: satella.coding.predicates.length_multiple_of
.. autofunction:: satella.coding.predicates.one_of
from .number import between
from .generic import one_of
from .generic import one_of, length_multiple_of, length_is
__all__ = ['between', 'one_of']
__all__ = ['between', 'one_of', 'length_is', 'length_multiple_of']
......@@ -10,3 +10,21 @@ def one_of(*args) -> tp.Callable[[tp.Any], bool]:
def predicate(v):
return v in args
return predicate
def length_multiple_of(x) -> tp.Callable[[tp.Sequence], bool]:
"""
Return a predicate that will return True if length of sequence is a multiple of x
"""
def predicate(v):
return not (len(v) % x)
return predicate
def length_is(x) -> tp.Callable[[tp.Sequence], bool]:
"""
Return a predicate that will return True if length of sequence is x
"""
def predicate(v):
return len(v) == x
return predicate
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment