class TxHashSet[V = Unsubscripted]
TxHashSet(ref) wraps an existing TxRef; empty, make,
from_iterable and from_hash_set are the effects.
Attributes#
| Attribute | Type | Description |
|---|---|---|
ref | TxRef[HashSet[V]] |
Functions#
__init__#
__init__(ref) -> None| Parameter | Type | Description |
|---|---|---|
ref | TxRef[HashSet[V]] |
def __init__(self, ref: TxRef[HashSet[V]]) -> None:
self._ref = refempty#
empty() -> Effect[TxHashSet[V]]Spelled TxHashSet[str].empty().
Returns Effect[TxHashSet[V]]
@classmethod
def empty(cls) -> Effect[TxHashSet[V]]:
"""Spelled ``TxHashSet[str].empty()``."""
return TxHashSet.from_hash_set(HashSet[V].empty())make#
make[T](*values: T = ()) -> Effect[TxHashSet[T]]
make(*values: V = ()) -> Effect[TxHashSet[V]]| Parameter | Type | Description |
|---|---|---|
values | = () |
@overload
@classmethod
def make[T](cls: type[TxHashSet[Unsubscripted]], *values: T) -> Effect[TxHashSet[T]]: ...
@overload
@classmethod
def make(cls, *values: V) -> Effect[TxHashSet[V]]: ...
@classmethod
def make[T](cls, *values: T) -> Effect[TxHashSet[T]]:
return TxHashSet.from_iterable(values)from_iterable#
from_iterable[T](values: Iterable[T]) -> Effect[TxHashSet[T]]
from_iterable(values: Iterable[V]) -> Effect[TxHashSet[V]]A new set each time the effect runs. values is read once,
here, so a one-shot iterator survives transaction retries.
| Parameter | Type | Description |
|---|---|---|
values |
@overload
@classmethod
def from_iterable[T](
cls: type[TxHashSet[Unsubscripted]], values: Iterable[T]
) -> Effect[TxHashSet[T]]: ...
@overload
@classmethod
def from_iterable(cls, values: Iterable[V]) -> Effect[TxHashSet[V]]: ...
@classmethod
def from_iterable[T](cls, values: Iterable[T]) -> Effect[TxHashSet[T]]:
"""A new set each time the effect runs. ``values`` is read once,
here, so a one-shot iterator survives transaction retries."""
return TxHashSet.from_hash_set(HashSet.from_iterable(values))from_hash_set#
from_hash_set[T](values: HashSet[T]) -> Effect[TxHashSet[T]]
from_hash_set(values: HashSet[V]) -> Effect[TxHashSet[V]]| Parameter | Type | Description |
|---|---|---|
values |
@overload
@classmethod
def from_hash_set[T](
cls: type[TxHashSet[Unsubscripted]], values: HashSet[T]
) -> Effect[TxHashSet[T]]: ...
@overload
@classmethod
def from_hash_set(cls, values: HashSet[V]) -> Effect[TxHashSet[V]]: ...
@classmethod
def from_hash_set[T](cls, values: HashSet[T]) -> Effect[TxHashSet[T]]:
return TxRef.make(values).map(TxHashSet)has#
has(value) -> Effect[bool]| Parameter | Type | Description |
|---|---|---|
value | V |
Returns Effect[bool]
def has(self, value: V) -> Effect[bool]:
return _tx_ops.read(self._ref, lambda s: s.has(value))size#
size() -> Effect[int]Returns Effect[int]
def size(self) -> Effect[int]:
return _tx_ops.read(self._ref, len)is_empty#
is_empty() -> Effect[bool]Returns Effect[bool]
def is_empty(self) -> Effect[bool]:
return _tx_ops.read(self._ref, HashSet[V].is_empty)is_non_empty#
is_non_empty() -> Effect[bool]Returns Effect[bool]
def is_non_empty(self) -> Effect[bool]:
return _tx_ops.read(self._ref, bool)to_hash_set#
to_hash_set() -> Effect[HashSet[V]]The set as it is now; HashSet is immutable, so it never
changes.
Returns Effect[HashSet[V]]
def to_hash_set(self) -> Effect[HashSet[V]]:
"""The set as it is now; ``HashSet`` is immutable, so it never
changes."""
return self._ref.get()is_subset#
is_subset(that) -> Effect[bool]Whether every value of this set is in that.
| Parameter | Type | Description |
|---|---|---|
that | TxHashSet[Any] |
Returns Effect[bool]
def is_subset(self, that: TxHashSet[Any]) -> Effect[bool]:
"""Whether every value of this set is in ``that``."""
return _tx_ops.read2(self._ref, that._ref, HashSet[V].is_subset)some#
some(predicate) -> Effect[bool]| Parameter | Type | Description |
|---|---|---|
predicate | Callable[[V], bool] |
Returns Effect[bool]
def some(self, predicate: Callable[[V], bool]) -> Effect[bool]:
return _tx_ops.read(self._ref, lambda s: s.some(predicate))every#
every(predicate) -> Effect[bool]| Parameter | Type | Description |
|---|---|---|
predicate | Callable[[V], bool] |
Returns Effect[bool]
def every(self, predicate: Callable[[V], bool]) -> Effect[bool]:
return _tx_ops.read(self._ref, lambda s: s.every(predicate))reduce#
reduce[A](zero, f) -> Effect[A]| Parameter | Type | Description |
|---|---|---|
zero | A | |
f | Callable[[A, V], A] |
Returns Effect[A]
def reduce[A](self, zero: A, f: Callable[[A, V], A]) -> Effect[A]:
return _tx_ops.read(self._ref, lambda s: s.reduce(zero, f))add#
add(value) -> Effect[None]Add value; a value already there leaves the same set, so the
ref's version stays.
| Parameter | Type | Description |
|---|---|---|
value | V |
Returns Effect[None]
def add(self, value: V) -> Effect[None]:
"""Add ``value``; a value already there leaves the same set, so the
ref's version stays."""
return self._ref.update(lambda s: s.add(value))remove#
remove(value) -> Effect[bool]Remove value; True when it was there.
| Parameter | Type | Description |
|---|---|---|
value | V |
Returns Effect[bool]
def remove(self, value: V) -> Effect[bool]:
"""Remove ``value``; ``True`` when it was there."""
return _tx_ops.modify_or_skip(
self._ref, lambda s: (True, Some(s.remove(value))) if s.has(value) else (False, None)
)clear#
clear() -> Effect[None]Returns Effect[None]
def clear(self) -> Effect[None]:
return self._ref.set(HashSet[V].empty())union#
union[V1](that) -> Effect[TxHashSet[V | V1]]| Parameter | Type | Description |
|---|---|---|
that | TxHashSet[V1] |
Returns Effect[TxHashSet[V | V1]]
def union[V1](self, that: TxHashSet[V1]) -> Effect[TxHashSet[V | V1]]:
return _tx_ops.read2(self._ref, that._ref, lambda a, b: TxHashSet(TxRef(a.union(b))))intersection#
intersection(that) -> Effect[TxHashSet[V]]| Parameter | Type | Description |
|---|---|---|
that | TxHashSet[Any] |
Returns Effect[TxHashSet[V]]
def intersection(self, that: TxHashSet[Any]) -> Effect[TxHashSet[V]]:
return _tx_ops.read2(self._ref, that._ref, lambda a, b: TxHashSet(TxRef(a.intersection(b))))difference#
difference(that) -> Effect[TxHashSet[V]]| Parameter | Type | Description |
|---|---|---|
that | TxHashSet[Any] |
Returns Effect[TxHashSet[V]]
def difference(self, that: TxHashSet[Any]) -> Effect[TxHashSet[V]]:
return _tx_ops.read2(self._ref, that._ref, lambda a, b: TxHashSet(TxRef(a.difference(b))))map#
map[U](f) -> Effect[TxHashSet[U]]| Parameter | Type | Description |
|---|---|---|
f | Callable[[V], U] |
Returns Effect[TxHashSet[U]]
def map[U](self, f: Callable[[V], U]) -> Effect[TxHashSet[U]]:
return _tx_ops.read(self._ref, lambda s: TxHashSet(TxRef(s.map(f))))filter#
filter[U](predicate: Callable[[V], TypeIs[U]]) -> Effect[TxHashSet[U]]
filter(predicate: Callable[[V], bool]) -> Effect[TxHashSet[V]]| Parameter | Type | Description |
|---|---|---|
predicate |
@overload
def filter[U](self, predicate: Callable[[V], TypeIs[U]]) -> Effect[TxHashSet[U]]: ...
@overload
def filter(self, predicate: Callable[[V], bool]) -> Effect[TxHashSet[V]]: ...
def filter(self, predicate: Callable[[V], bool]) -> Effect[TxHashSet[Any]]:
return _tx_ops.read(self._ref, lambda s: TxHashSet(TxRef(s.filter(predicate))))