Skip to content

Commit

Permalink
Var is now public
Browse files Browse the repository at this point in the history
  • Loading branch information
salt-die committed Dec 7, 2023
1 parent 48c755f commit d87cdd8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/mind_the_gaps/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""A library for unions, intersections, subtractions, and xors of intervals (gaps)."""
from .gaps import Endpoint, Gaps
from .var import x
from .var import Var, x

__all__ = ["Endpoint", "Gaps", "x"]
__all__ = ["Endpoint", "Gaps", "Var", "x"]

__version__ = "0.3.0"
28 changes: 24 additions & 4 deletions src/mind_the_gaps/var.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,31 @@

from .gaps import Endpoint, SupportsLessThan

__all__ = ["x"]
__all__ = ["Var", "x"]


@dataclass
class _Var[T: SupportsLessThan]:
class Var[T: SupportsLessThan]:
"""
A very convenient constructor for `Endpoints`.
It's best to start with an example::
>>> from mind_the_gaps import Gaps, Var
>>> x = Var("x")
>>> 0 <= x
Endpoint(value=0, boundary='[')
>>> x < 1
Endpoint(value=1, boundary=')')
>>> print(Gaps([0 <= x, x < 1]))
{[0, 1)}
Values compared with a Var will return an endpoint. The type of comparison determines
the boundary of the endpoint. `>` is left-open, `>=` is left-closed, `<` is right-open,
and `<=` is right-closed.
`Var("x")` can be imported directly as `x`, e.g., `from mind_the_gaps import x`.
"""

name: str

def __str__(self):
Expand All @@ -25,12 +45,12 @@ def __le__(self, value: T) -> Endpoint:
return Endpoint(value, "]")


x = _Var("x")
x = Var("x")
"""
A very convenient constructor for `Endpoints`.
It's best to start with an example::
>>> from mind_the_gaps import x
>>> from mind_the_gaps import Gaps, x
>>> 0 <= x
Endpoint(value=0, boundary='[')
>>> x < 1
Expand Down

0 comments on commit d87cdd8

Please sign in to comment.