nustack
ReferenceNuformscollectionsabc

container

Container capability.

Module nu.forms.collections.abc.container.

Container capability.

ContainerForm: values that support containment checks.

Follows Python's collections.abc.Container pattern.

NameCallMeaning
ContainerFormContainerForm()Base for values that support containment checks, like collections.abc.Container.

ContainerForm

Base for values that support containment checks, like collections.abc.Container.

ContainerForm()

Path nu.forms.collections.abc.ContainerForm.

Notes

  • Python's in operator coerces __contains__'s result to bool at the C level, which would collapse the Nu tree to a constant True. .contains(item) returns a real Bool tree node instead.

Example

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

Methods

.contains(item)

Whether item is a member of self.

Builds Bool.

Arguments

NameTypeDefaultMeaning
itemobjectthe value to test for membership.

Yields

True when item is in self, False otherwise. INVALID when self or item is a sentinel.

Examples

nu.run(nu.Set({1, 2, 3}).contains(2))[0]
True
nu.run(nu.Set({1, 2, 3}).contains(9))[0]
False

Inherited methods

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.

From builtins.object:

CallBuildsMeaning
a < bReturn self<value.
a <= bReturn self<=value.
a == bReturn self==value.
a != bReturn self!=value.
a > bReturn self>value.
a >= bReturn self>=value.

On this page