Skip to content

Commit

Permalink
Add felis.predicate.interval and felis.predicate.float.portion, f…
Browse files Browse the repository at this point in the history
…ormat `__all__`s
  • Loading branch information
LeeeeT committed Jun 11, 2024
1 parent be26539 commit d176f69
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 42 deletions.
13 changes: 1 addition & 12 deletions src/felis/constrained/float.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,7 @@
import felis.predicate.float
from felis.constrained import smart_constructor

__all__ = [
"Negative",
"negative",
"NonPositive",
"non_positive",
"NonZero",
"non_zero",
"NonNegative",
"non_negative",
"Positive",
"positive",
]
__all__ = ["Negative", "negative", "NonPositive", "non_positive", "NonZero", "non_zero", "NonNegative", "non_negative", "Positive", "positive"]


Negative = NewType("Negative", float)
Expand Down
13 changes: 1 addition & 12 deletions src/felis/constrained/int.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,7 @@
import felis.predicate.float
from felis.constrained import smart_constructor

__all__ = [
"Negative",
"negative",
"NonPositive",
"non_positive",
"NonZero",
"non_zero",
"NonNegative",
"non_negative",
"Positive",
"positive",
]
__all__ = ["Negative", "negative", "NonPositive", "non_positive", "NonZero", "non_zero", "NonNegative", "non_negative", "Positive", "positive"]


Negative = NewType("Negative", int)
Expand Down
4 changes: 2 additions & 2 deletions src/felis/predicate/bool.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from felis import predicate
from felis.predicate import negate

__all__ = ["truthy", "falsey"]

Expand All @@ -7,4 +7,4 @@ def truthy(value: object) -> bool:
return bool(value)


falsey = predicate.negate(truthy)
falsey = negate(truthy)
9 changes: 1 addition & 8 deletions src/felis/predicate/comparison.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
from felis.currying import curry
from felis.typing import SupportsRichComparison

__all__ = [
"less",
"less_or_equal",
"equal",
"not_equal",
"greater_or_equal",
"greater",
]
__all__ = ["less", "less_or_equal", "equal", "not_equal", "greater_or_equal", "greater"]


@curry
Expand Down
13 changes: 5 additions & 8 deletions src/felis/predicate/float.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
from felis.predicate import comparison
from felis.predicate import comparison, interval

__all__ = [
"negative",
"non_positive",
"non_zero",
"non_negative",
"positive",
]
__all__ = ["negative", "non_positive", "non_zero", "non_negative", "positive", "portion"]


negative = comparison.less(0.0)
Expand All @@ -22,3 +16,6 @@


positive = comparison.greater(0.0)


portion = interval.inclusive(0.0)(1.0)
25 changes: 25 additions & 0 deletions src/felis/predicate/interval.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from felis.currying import curry
from felis.predicate import Predicate, both, comparison
from felis.typing import SupportsRichComparison

__all__ = ["inclusive", "inclusive_exclusive", "exclusive_inclusive", "exclusive"]


@curry
def inclusive[T: SupportsRichComparison](maximum: T, minimum: T) -> Predicate[T]:
return both(comparison.greater_or_equal(minimum))(comparison.less_or_equal(maximum))


@curry
def inclusive_exclusive[T: SupportsRichComparison](maximum: T, minimum: T) -> Predicate[T]:
return both(comparison.greater_or_equal(minimum))(comparison.less(maximum))


@curry
def exclusive_inclusive[T: SupportsRichComparison](maximum: T, minimum: T) -> Predicate[T]:
return both(comparison.greater(minimum))(comparison.less_or_equal(maximum))


@curry
def exclusive[T: SupportsRichComparison](maximum: T, minimum: T) -> Predicate[T]:
return both(comparison.greater(minimum))(comparison.less(maximum))

0 comments on commit d176f69

Please sign in to comment.