Predicates and factories¶
Predicates are functions that return a boolean value given a single argument. These modules contain predicate functions, and functions that return predicates, that can be composed and used for phantom types.
Boolean logic¶
-
phantom.predicates.boolean.
true
(_value)[source]¶ Always return
True
.- Parameters
_value (
object
) –- Return type
typing.Literal
[True]
-
phantom.predicates.boolean.
false
(_value)[source]¶ Always return
False
.- Parameters
_value (
object
) –- Return type
typing.Literal
[False]
-
phantom.predicates.boolean.
negate
(predicate)[source]¶ Negate a given predicate.
- Parameters
predicate (
typing.Callable
[[-T],bool
]) –- Return type
typing.Callable
[[-T],bool
]
-
phantom.predicates.boolean.
truthy
(value)[source]¶ Return
True
for truthy objects.- Parameters
value (
object
) –- Return type
bool
-
phantom.predicates.boolean.
falsy
(value)[source]¶ Return
True
for falsy objects.- Parameters
value (
object
) –- Return type
bool
-
phantom.predicates.boolean.
both
(p, q)[source]¶ Create a new predicate that succeeds when both of the given predicates succeed.
- Parameters
p (
typing.Callable
[[-T],bool
]) –q (
typing.Callable
[[-T],bool
]) –
- Return type
typing.Callable
[[-T],bool
]
-
phantom.predicates.boolean.
either
(p, q)[source]¶ Create a new predicate that succeeds when at least one of the given predicates succeed.
- Parameters
p (
typing.Callable
[[-T],bool
]) –q (
typing.Callable
[[-T],bool
]) –
- Return type
typing.Callable
[[-T],bool
]
-
phantom.predicates.boolean.
xor
(p, q)[source]¶ Create a new predicate that succeeds when one of the given predicates succeed, but not both.
- Parameters
p (
typing.Callable
[[-T],bool
]) –q (
typing.Callable
[[-T],bool
]) –
- Return type
typing.Callable
[[-T],bool
]
-
phantom.predicates.boolean.
all_of
(predicates)[source]¶ Create a new predicate that succeeds when all of the given predicates succeed.
- Parameters
predicates (
typing.Iterable
[typing.Callable
[[-T],bool
]]) –- Return type
typing.Callable
[[-T],bool
]
Collection¶
-
phantom.predicates.collection.
contains
(value)[source]¶ Create a new predicate that succeeds when its argument contains
value
.- Parameters
value (
object
) –- Return type
typing.Callable
[[Container
],bool
]
-
phantom.predicates.collection.
contained
(container)[source]¶ Create a new predicate that succeeds when its argument is contained by
container
.- Parameters
container (
typing.Container
) –- Return type
typing.Callable
[[object
],bool
]
-
phantom.predicates.collection.
count
(predicate)[source]¶ Create a predicate that succeeds when the size of its argument satisfies the given
predicate
.- Parameters
predicate (
typing.Callable
[[int
],bool
]) –- Return type
typing.Callable
[[Sized
],bool
]
Datetime¶
Generic¶
-
phantom.predicates.generic.
equal
(a)[source]¶ Create a new predicate that succeeds when its argument is equal to
a
.- Parameters
a (
object
) –- Return type
typing.Callable
[[object
],bool
]