nustack

sliceable

Sliceable capability.

Module nu.forms.collections.abc.sliceable.

Sliceable capability.

SliceableForm: values that support slicing.

NameCallMeaning
SliceableFormSliceableForm()Base for values that support slicing.

SliceableForm

Base for values that support slicing.

SliceableForm()

Path nu.forms.collections.abc.SliceableForm.

Example

nu.run(nu.List([1, 2, 3, 4, 5]).slice(1, 4))[0]
[2, 3, 4]

Methods

.slice(start, stop, step=None)

Slice of self from start to stop, stepping by step.

Builds ResultT.

Arguments

NameTypeDefaultMeaning
startIntArg | Nonethe index to start at, inclusive. None starts from the beginning.
stopIntArg | Nonethe index to stop at, exclusive. None runs to the end.
stepIntArg | NoneNonethe stride between elements. None means every element.

Yields

The sliced value, wrapped by the subclass. EMPTY when self is EMPTY.

Notes

  • Bounds are clamped like Python slicing: an out-of-range start or stop never raises.

Examples

nu.run(nu.List([1, 2, 3, 4, 5]).slice(1, 4))[0]
[2, 3, 4]
nu.run(nu.List([1, 2, 3, 4, 5]).slice(0, 5, 2))[0]
[1, 3, 5]

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