[docs]defless(n:T)->Predicate[SupportsLt[T]]:""" Create a new predicate that succeeds when its argument is strictly less than ``n``. """@bind_name(less,n)defcheck(value:SupportsLt[T])->bool:returnvalue<nreturncheck
[docs]defle(n:T)->Predicate[SupportsLe[T]]:""" Create a new predicate that succeeds when its argument is less than or equal to ``n``. """@bind_name(le,n)defcheck(value:SupportsLe[T])->bool:returnvalue<=nreturncheck
[docs]defgreater(n:T)->Predicate[SupportsGt[T]]:""" Create a new predicate that succeeds when its argument is strictly greater than ``n``. """@bind_name(greater,n)defcheck(value:SupportsGt[T])->bool:returnvalue>nreturncheck
[docs]defge(n:T)->Predicate[SupportsGe[T]]:""" Create a new predicate that succeeds when its argument is greater than or equal to ``n``. """@bind_name(ge,n)defcheck(value:SupportsGe[T])->bool:returnvalue>=nreturncheck
[docs]defpositive(n:SupportsGt[int])->bool:"""Return :py:const:`True` when ``n`` is strictly greater than zero."""returngreater(0)(n)
[docs]defnon_positive(n:SupportsLe[int])->bool:"""Return :py:const:`True` when ``n`` is less than or equal to zero."""returnle(0)(n)
[docs]defnegative(n:SupportsLt[int])->bool:"""Return :py:const:`True` when ``n`` is strictly less than zero."""returnless(0)(n)
[docs]defnon_negative(n:SupportsGe[int])->bool:"""Return :py:const:`True` when ``n`` is greater than or equal to zero."""returnge(0)(n)
[docs]defmodulo(n:T,p:Predicate[U])->Predicate[SupportsMod[T,U]]:""" Create a new predicate that succeeds when its argument modulo ``n`` satisfies the given predicate ``p``. """@bind_name(modulo,n,p)defcheck(value:SupportsMod[T,U])->bool:returnp(value%n)returncheck
[docs]defeven(n:int)->bool:"""Return :py:const:`True` when ``n`` is even."""returnmodulo(2,equal(0))(n)
[docs]defodd(n:int)->bool:"""Return :py:const:`True` when ``n`` is odd."""returnnegate(even)(n)