Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions expression/collections/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@
from collections.abc import Callable, ItemsView, Iterable, Iterator, Mapping
from typing import Any, TypeVar, cast

from expression.core import Option, PipeMixin, SupportsLessThan, curry_flip, pipe
from expression.core import Option, PipeMixin, curry_flip, pipe
from expression.core.typing import SupportsLessThanAndHash

from . import maptree, seq
from .block import Block
from .maptree import MapTree


_Key = TypeVar("_Key", bound=SupportsLessThan)
_Key_ = TypeVar("_Key_", bound=SupportsLessThan)
_Key = TypeVar("_Key", bound=SupportsLessThanAndHash)
_Key_ = TypeVar("_Key_", bound=SupportsLessThanAndHash)
_Value = TypeVar("_Value")
_Result = TypeVar("_Result")

Expand Down
11 changes: 6 additions & 5 deletions expression/collections/maptree.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,18 @@
"""

import builtins
from collections.abc import Callable, Iterable, Iterator
from collections.abc import Callable, Hashable, Iterable, Iterator
from dataclasses import dataclass
from typing import Any, Generic, TypeVar

from expression.core import Nothing, Option, Some, SupportsLessThan, failwith, pipe
from expression.core import Nothing, Option, Some, failwith, pipe
from expression.core.typing import SupportsLessThanAndHash

from . import block, seq
from .block import Block


Key = TypeVar("Key", bound=SupportsLessThan)
Key = TypeVar("Key", bound=SupportsLessThanAndHash)
Value = TypeVar("Value")
Result = TypeVar("Result")

Expand All @@ -55,7 +56,7 @@ class MapTreeNode(MapTreeLeaf[Key, Value]):
height: int


empty: MapTree[Any, Any] = Nothing
empty: MapTree[Hashable, Any] = Nothing


def is_empty(m: MapTree[Any, Any]):
Expand All @@ -72,7 +73,7 @@ def size_aux(acc: int, m: MapTree[Key, Value]) -> int:
return acc


def size(x: MapTree[Any, Any]):
def size(x: MapTree[Hashable, Any]):
return size_aux(0, x)


Expand Down
5 changes: 5 additions & 0 deletions expression/core/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ def __lt__(self, __other: Any) -> bool:
raise NotImplementedError


class SupportsLessThanAndHash(SupportsLessThan, Protocol):
def __hash__(self) -> int:
return super().__hash__()


class SupportsSum(Protocol):
@abstractmethod
def __radd__(self, __other: Any) -> Any:
Expand Down