Range

package
v0.0.0-...-0b2f126 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 3, 2026 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(begin, end int64, options ...Option) Result.Interface

New is the Range constructor.

It yields a Result whose payload is a Range over [begin, end] with a step of 1 and an inclusive end. The end can be excluded with Exclusive() and the step set with WithStep(). A zero step is invalid and produces a Result carrying an Error ("step cannot be zero") instead of a payload — construction never panics and never returns nil.

r1 := Range.New(1, 5)                              // 1..5  step 1
r2 := Range.New(1, 5, Range.Exclusive())           // 1...5
r3 := Range.New(0, 10, Range.WithStep(2))          // 0,2,4,6,8,10

Types

type Interface

type Interface interface {
	Begin() Number.Interface
	End() Number.Interface
	Step() Number.Interface
	ExcludesEnd() bool
	Includes(n int64) bool
	Len() int
	IsEmpty() bool
	Each(fn func(Number.Interface) Result.Interface) Result.Interface
	ToArray() Array.Interface
	IsNull() bool
}

Range is a numeric interval composite over Go int64 bounds.

Modelled on Ruby's Range, it supports both an inclusive end (Ruby's "1..5") and an exclusive end (Ruby's "1...5"), and a non-zero integer step. Its fallible construction returns a Result.Interface so an invalid step (zero) is a value rather than a panic. The elements it exposes are go-composites Numbers.

Note: Range is deliberately integer-only — its bounds and step are Go int64 values — which keeps element enumeration and coverage tractable.

type Option

type Option func(*data)

func Exclusive

func Exclusive() Option

Exclusive is a functional parameter making the Range exclude its end bound (Ruby's "1...5").

func WithStep

func WithStep(step int64) Option

WithStep is a functional parameter setting the Range step.

The step must be non-zero; New returns an error Result when it is zero.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL