nustack

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. EMPTY when self or item is EMPTY.

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
a == bBoolSelf equal to other by value: an Eq term, never a Python bool.
a != bBoolSelf not equal to other by value: a Ne term, never a Python bool.
.is_empty()BoolTrue if this Form yields the EMPTY sentinel.
.not_empty()BoolTrue if this Form does not yield EMPTY.
.fallback(*alternatives)SelfThe first of this value and alternatives that is not EMPTY.

From builtins.object:

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

On this page