nustack
ReferenceNuforms

collections.set_

Set, FrozenSet - set interfaces.

Module nu.forms.collections.set_.

Set, FrozenSet - set interfaces.

NameSortCallMeaning
FrozenSetscalar_queryFrozenSet()FrozenSet interface. Immutable set + comparable.
Setscalar_querySet()Set interface. Mutable set + comparable.

FrozenSet

FrozenSet interface. Immutable set + comparable.

FrozenSet()

Path nu.forms.FrozenSet. Kind ScalarQuery, sort scalar_query, cardinality scalar.

Notes

  • Iteration order is arbitrary, matching Python's frozenset.
  • >, <, >=, <= are subset/superset relations, not size comparisons. union, intersection, difference, symmetric_difference and the operators |, &, -, ^ live on the shared set base, not on this class.
  • No add/remove/update/... unlike Set: a FrozenSet can't be mutated in place.

Example

nu.run(nu.FrozenSet.of(1, 2, 3))[0]
frozenset({1, 2, 3})

Methods

FrozenSet.create()

Build an empty frozenset.

Builds FrozenSet[T].

Yields

An empty FrozenSet.

Example

nu.run(nu.FrozenSet.create())[0]
frozenset()

FrozenSet.of(*items)

Build a frozenset from positional item expressions.

Builds FrozenSet.

Arguments

NameTypeDefaultMeaning
*itemsexpressions to evaluate and fold into the frozenset, in any order.

Yields

A fresh FrozenSet holding the evaluated items. INVALID when any item is a sentinel.

Notes

  • Sibling to Set.of. Duplicate values collapse, same as Python frozenset construction.

Example

nu.run(nu.FrozenSet.of(1, 2, 2, 3))[0]
frozenset({1, 2, 3})

a > b

Self is a proper superset of other.

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherFrozenSetArg[T]the set to compare against.

Yields

True when self contains every element of other and at least one more, False otherwise. INVALID when either operand is a sentinel.

Example

nu.run(nu.FrozenSet.of(1, 2, 3) > nu.FrozenSet.of(1, 2))[0]
True

a < b

Self is a proper subset of other.

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherFrozenSetArg[T]the set to compare against.

Yields

True when every element of self is in other and other has at least one more, False otherwise. INVALID when either operand is a sentinel.

Example

nu.run(nu.FrozenSet.of(1, 2) < nu.FrozenSet.of(1, 2, 3))[0]
True

a >= b

Self is a superset of other, or equal.

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherFrozenSetArg[T]the set to compare against.

Yields

True when every element of other is in self, False otherwise. INVALID when either operand is a sentinel.

Example

nu.run(nu.FrozenSet.of(1, 2) >= nu.FrozenSet.of(1, 2))[0]
True

a <= b

Self is a subset of other, or equal.

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherFrozenSetArg[T]the set to compare against.

Yields

True when every element of self is in other, False otherwise. INVALID when either operand is a sentinel.

Example

nu.run(nu.FrozenSet.of(1, 2) <= nu.FrozenSet.of(1, 2))[0]
True

a == b

Self equal to other by value.

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherFrozenSetArg[T]the set to compare against.

Yields

True when the sets hold the same elements, False otherwise. INVALID when either operand is a sentinel.

Notes

  • Value equality, not identity. Use is_ for identity. Two sets compare equal regardless of insertion or iteration order.

Example

nu.run(nu.FrozenSet.of(1, 2) == nu.FrozenSet.of(2, 1))[0]
True

a != b

Self not equal to other by value.

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherFrozenSetArg[T]the set to compare against.

Yields

True when the sets differ, False otherwise. INVALID when either operand is a sentinel.

Notes

  • Value inequality, not identity. Use is_ for identity.

Example

nu.run(nu.FrozenSet.of(1, 2) != nu.FrozenSet.of(1, 3))[0]
True

.is_(other)

Identity comparison: self is other.

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherFrozenSetArg[T]the value to compare identity against.

Yields

True when self and other evaluate to the same Python object, False otherwise.

Notes

  • Object identity, not value equality. For value comparison use == instead.

Example

nu.run(nu.FrozenSet.of(1, 2).is_(nu.FrozenSet.of(1, 2)))[0]
False

Inherited methods

From nu.forms.collections.abc.set_.SetLikeForm:

CallBuildsMeaning
.union(other)CollectionResultTUnion of self and other.
.intersection(other)CollectionResultTIntersection of self and other.
.difference(other)CollectionResultTElements of self that are not in other.
.symmetric_difference(other)CollectionResultTElements in exactly one of self and other, not both.
.issubset(other)BoolWhether every element of self is in other.
.issuperset(other)BoolWhether every element of other is in self.
.isdisjoint(other)BoolWhether self and other share no elements.
.copy()CollectionResultTShallow copy of self.
a | bCollectionResultTUnion: self | other.
a & bCollectionResultTIntersection: self & other.
a - bCollectionResultTDifference: self - other.
a ^ bCollectionResultTSymmetric difference: self ^ other.

From nu.forms.collections.abc.collection.CollectionForm:

CallBuildsMeaning
.extract()objectMaterialise the full subtree rooted at self.

From nu.forms.collections.abc.sized.SizedForm:

CallBuildsMeaning
.len()IntLength of self.

From nu.forms.collections.abc.iterable.IterableForm:

CallBuildsMeaning
iter(a)Iterator[ElementT]Open self into a lazy iterator stream (Python's iter).

From nu.forms.collections.abc.container.ContainerForm:

CallBuildsMeaning
.contains(item)BoolWhether item is a member of self.

From nu.lang.forms.Form:

CallBuildsMeaning
.is_empty()BoolTrue if this Form yields the EMPTY sentinel.
.is_invalid()BoolTrue if this Form yields the INVALID sentinel.
.is_sentinel()BoolTrue if this Form yields either sentinel (EMPTY or INVALID).
.not_empty()BoolTrue if this Form does not yield EMPTY.
.not_invalid()BoolTrue if this Form does not yield INVALID.

Set

Set interface. Mutable set + comparable.

Set()

Path nu.forms.Set. Kind ScalarQuery, sort scalar_query, cardinality scalar.

Notes

  • Iteration order is arbitrary, matching Python's set. Don't rely on insertion order surviving a round trip.
  • >, <, >=, <= are subset/superset relations, not size comparisons: a > b means a is a proper superset of b, not that a has more elements. union, intersection, difference, symmetric_difference and the operators |, &, -, ^ live on the shared set base, not on this class.
  • Mutating ops (add, remove, discard, pop, clear, update, ...) live on the shared mutable-set base too.

Example

nu.run(nu.Set.of(1, 2, 3))[0]
{1, 2, 3}

Methods

Set.create()

Build a fresh empty set.

Builds Set[T].

Yields

An empty Set.

Example

nu.run(nu.Set.create())[0]
set()

Set.of(*items)

Build a set from positional item expressions.

Builds Set.

Arguments

NameTypeDefaultMeaning
*itemsexpressions to evaluate and fold into the set, in any order.

Yields

A fresh Set holding the evaluated items. INVALID when any item is a sentinel.

Notes

  • Sibling to List.of / Tuple.of. Duplicate values collapse, same as Python set construction.

Example

nu.run(nu.Set.of(1, 2, 2, 3))[0]
{1, 2, 3}

a > b

Self is a proper superset of other.

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherSetArg[T]the set to compare against.

Yields

True when self contains every element of other and at least one more, False otherwise. INVALID when either operand is a sentinel.

Example

nu.run(nu.Set.of(1, 2, 3) > nu.Set.of(1, 2))[0]
True

a < b

Self is a proper subset of other.

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherSetArg[T]the set to compare against.

Yields

True when every element of self is in other and other has at least one more, False otherwise. INVALID when either operand is a sentinel.

Example

nu.run(nu.Set.of(1, 2) < nu.Set.of(1, 2, 3))[0]
True

a >= b

Self is a superset of other, or equal.

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherSetArg[T]the set to compare against.

Yields

True when every element of other is in self, False otherwise. INVALID when either operand is a sentinel.

Example

nu.run(nu.Set.of(1, 2) >= nu.Set.of(1, 2))[0]
True

a <= b

Self is a subset of other, or equal.

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherSetArg[T]the set to compare against.

Yields

True when every element of self is in other, False otherwise. INVALID when either operand is a sentinel.

Example

nu.run(nu.Set.of(1, 2) <= nu.Set.of(1, 2))[0]
True

a == b

Self equal to other by value.

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherSetArg[T]the set to compare against.

Yields

True when the sets hold the same elements, False otherwise. INVALID when either operand is a sentinel.

Notes

  • Value equality, not identity. Use is_ for identity. Two sets compare equal regardless of insertion or iteration order.

Example

nu.run(nu.Set.of(1, 2) == nu.Set.of(2, 1))[0]
True

a != b

Self not equal to other by value.

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherSetArg[T]the set to compare against.

Yields

True when the sets differ, False otherwise. INVALID when either operand is a sentinel.

Notes

  • Value inequality, not identity. Use is_ for identity.

Example

nu.run(nu.Set.of(1, 2) != nu.Set.of(1, 3))[0]
True

.is_(other)

Identity comparison: self is other.

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherSetArg[T]the value to compare identity against.

Yields

True when self and other evaluate to the same Python object, False otherwise.

Notes

  • Object identity, not value equality. For value comparison use == instead.

Example

nu.run(nu.Set.of(1, 2).is_(nu.Set.of(1, 2)))[0]
False

Inherited methods

From nu.forms.collections.abc.set_.MutableSetForm:

CallBuildsMeaning
.add(value)AnyAdd value to self.
.remove(value)AnyRemove value from self.
.discard(value)AnyRemove value from self if present.
.pop()ElementResultTRemove and return an arbitrary element from self.
.clear()AnyRemove every element from self.
.update(other)AnyAdd every element of other to self.
.intersection_update(other)AnyKeep only the elements of self also found in other.
.difference_update(other)AnyRemove every element of other from self.
.symmetric_difference_update(other)AnyKeep the elements in exactly one of self and other.

From nu.forms.collections.abc.set_.SetLikeForm:

CallBuildsMeaning
.union(other)CollectionResultTUnion of self and other.
.intersection(other)CollectionResultTIntersection of self and other.
.difference(other)CollectionResultTElements of self that are not in other.
.symmetric_difference(other)CollectionResultTElements in exactly one of self and other, not both.
.issubset(other)BoolWhether every element of self is in other.
.issuperset(other)BoolWhether every element of other is in self.
.isdisjoint(other)BoolWhether self and other share no elements.
.copy()CollectionResultTShallow copy of self.
a | bCollectionResultTUnion: self | other.
a & bCollectionResultTIntersection: self & other.
a - bCollectionResultTDifference: self - other.
a ^ bCollectionResultTSymmetric difference: self ^ other.

From nu.forms.collections.abc.collection.CollectionForm:

CallBuildsMeaning
.extract()objectMaterialise the full subtree rooted at self.

From nu.forms.collections.abc.sized.SizedForm:

CallBuildsMeaning
.len()IntLength of self.

From nu.forms.collections.abc.iterable.IterableForm:

CallBuildsMeaning
iter(a)Iterator[ElementT]Open self into a lazy iterator stream (Python's iter).

From nu.forms.collections.abc.container.ContainerForm:

CallBuildsMeaning
.contains(item)BoolWhether item is a member of self.

From nu.lang.forms.Form:

CallBuildsMeaning
.is_empty()BoolTrue if this Form yields the EMPTY sentinel.
.is_invalid()BoolTrue if this Form yields the INVALID sentinel.
.is_sentinel()BoolTrue if this Form yields either sentinel (EMPTY or INVALID).
.not_empty()BoolTrue if this Form does not yield EMPTY.
.not_invalid()BoolTrue if this Form does not yield INVALID.

On this page