nustack
ReferenceNuformscollectionsabc

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. INVALID when self is a sentinel.

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
.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