container
Container capability.
Module nu.forms.collections.abc.container.
Container capability.
ContainerForm: values that support containment checks.
Follows Python's collections.abc.Container pattern.
| Name | Call | Meaning |
|---|---|---|
| ContainerForm | ContainerForm() | 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
inoperator coerces__contains__'s result toboolat the C level, which would collapse the Nu tree to a constantTrue..contains(item)returns a real Bool tree node instead.
Example
nu.run(nu.Set({1, 2, 3}).contains(2))[0]TrueMethods
.contains(item)
Whether item is a member of self.
Builds Bool.
Arguments
| Name | Type | Default | Meaning |
|---|---|---|---|
item | object | the 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]Truenu.run(nu.Set({1, 2, 3}).contains(9))[0]FalseInherited methods
From nu.lang.forms.Form:
| Call | Builds | Meaning |
|---|---|---|
a == b | Bool | Self equal to other by value: an Eq term, never a Python bool. |
a != b | Bool | Self not equal to other by value: a Ne term, never a Python bool. |
.is_empty() | Bool | True if this Form yields the EMPTY sentinel. |
.not_empty() | Bool | True if this Form does not yield EMPTY. |
.fallback(*alternatives) | Self | The first of this value and alternatives that is not EMPTY. |
From builtins.object:
| Call | Builds | Meaning |
|---|---|---|
a < b | Return self<value. | |
a <= b | Return self<=value. | |
a > b | Return self>value. | |
a >= b | Return self>=value. |