granges

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2025 License: MIT Imports: 2 Imported by: 0

README

granges

Go Version

A powerful mathematical interval operation library for Go, ported from Google Guava's Range. granges provides comprehensive support for creating, manipulating, and performing operations on ranges (intervals) of comparable values.

Features

  • Type-safe intervals using Go generics for any comparable type
  • Nine types of ranges including open, closed, half-open, and unbounded ranges
  • Rich set operations including intersection, union (span), gap analysis, and containment checking
  • Immutable design ensuring thread safety
  • Comprehensive API with both error-returning and panic-free variants
  • Full test coverage ensuring reliability

Installation

go get -u github.com/AyakuraYuki/granges

Quick Start

package main

import (
	"fmt"

	"github.com/AyakuraYuki/granges"
)

func main() {
	// Create a closed range [1, 10]
	r1 := granges.Closed(1, 10)
	fmt.Println(r1.Contains(5))
	fmt.Println(r1.Contains(15))
	// Output:
	// true
	// false

	// Create an open range (0, 20)
	r2 := granges.Open(0, 20)

	// Find intersection
	intersection := r1.Intersection(r2)
	fmt.Println(intersection)
	// Output:
	// [1, 10]

	// Create unbounded ranges
	atLeast5 := granges.AtLeast(5)
	lessThan100 := granges.LessThan(100)
	fmt.Println(atLeast5.String())
	fmt.Println(lessThan100.String())
	// Output:
	// [5, +∞)
	// (-∞, 100)
}

Range Types

granges supports nine fundamental types of ranges:

Type Notation Description Example
Open (a, b) {x | a < x < b} granges.Open(1, 5)
Closed [a, b] {x | a ≤ x ≤ b} granges.Closed(1, 5)
OpenClosed (a, b] {x | a < x ≤ b} granges.OpenClosed(1, 5)
ClosedOpen [a, b) {x | a ≤ x < b} granges.ClosedOpen(1, 5)
GreaterThan (a, +∞) {x | x > a} granges.GreaterThan(5)
AtLeast [a, +∞) {x | x ≥ a} granges.AtLeast(5)
LessThan (-∞, b) {x | x < b} granges.LessThan(10)
AtMost (-∞, b] {x | x ≤ b} granges.AtMost(10)
All (-∞, +∞) {x} granges.All[int]()
Supported Types

The library works with any comparable type:

  • Integers: int, int8, int16, int32, int64
  • Unsigned integers: uint, uint8, uint16, uint32, uint64
  • Floating point: float32, float64
  • Strings: string

Creating Ranges

Basic Range Creation
package main

import "github.com/AyakuraYuki/granges"

func main() {
	// Bounded ranges
	closed := granges.Closed(1, 10)        // [1, 10]
	open := granges.Open(1, 10)            // (1, 10)
	halfOpen1 := granges.ClosedOpen(1, 10) // [1, 10)
	halfOpen2 := granges.OpenClosed(1, 10) // (1, 10]

	// Unbounded ranges
	atLeast := granges.AtLeast(5)         // [5, +∞)
	greaterThan := granges.GreaterThan(5) // (5, +∞)
	atMost := granges.AtMost(10)          // (-∞, 10]
	lessThan := granges.LessThan(10)      // (-∞, 10)

	// Special ranges
	singleton := granges.Singleton(42) // [42, 42]
	all := granges.All[int]()          // (-∞, +∞)
}

Advanced Range Creation
package main

import (
	"log"

	"github.com/AyakuraYuki/granges"
)

func main() {
	// Custom bound types
	r := granges.New(1, granges.CLOSED, 10, granges.OPEN) // [1, 10)

	// Error-handling variants
	r, err := granges.ClosedE(10, 1) // Returns error for invalid range
	if err != nil {
		log.Fatal(err)
	}

	// Directional ranges
	upTo, _ := granges.UpTo(100, granges.CLOSED) // (-∞, 100]
	downTo, _ := granges.DownTo(0, granges.OPEN) // (0, +∞)
}

Range Operations

Containment Testing
package main

import (
	"fmt"

	"github.com/AyakuraYuki/granges"
)

func main() {
	r := granges.Closed(1, 10)

	// Single value
	fmt.Println(r.Contains(5))  // true
	fmt.Println(r.Contains(15)) // false

	// Multiple values
	values := []int{2, 5, 8}
	fmt.Println(r.ContainsAll(values)) // true

	// Range enclosure
	inner := granges.Closed(3, 7)
	fmt.Println(r.Encloses(inner)) // true
}

Set Operations
package main

import (
	"fmt"

	"github.com/AyakuraYuki/granges"
)

func main() {
	r1 := granges.Closed(1, 10)
	r2 := granges.Closed(5, 15)

	// Intersection - overlapping part
	intersection := r1.Intersection(r2) // [5, 10]

	// Span - minimal range covering both
	span := r1.Span(r2) // [1, 15]

	// Gap - range between two non-overlapping ranges
	r3 := granges.Closed(20, 30)
	gap := r1.Gap(r3) // (10, 20)

	// Connectivity test
	fmt.Println(r1.IsConnected(r2)) // true
	fmt.Println(r1.IsConnected(r3)) // false
}
Range Properties
package main

import (
	"fmt"
	"log"

	"github.com/AyakuraYuki/granges"
)

func main() {
	r := granges.ClosedOpen(5, 10)

	// Bounds checking
	fmt.Println(r.HasLowerBound()) // true
	fmt.Println(r.HasUpperBound()) // true

	// Endpoint access
	fmt.Println(r.LowerEndpoint()) // 5
	fmt.Println(r.UpperEndpoint()) // 10

	// Bound types
	fmt.Println(r.LowerBoundType()) // CLOSED
	fmt.Println(r.UpperBoundType()) // OPEN

	// Special properties
	fmt.Println(r.IsEmpty()) // false

	// Safe endpoint access with error handling
	endpoint, err := r.LowerEndpointE()
	if err != nil {
		log.Printf("No lower bound: %v", err)
	}
}

Error Handling

The library provides two API patterns:

  1. Simple API: Returns zero values for errors, suitable when you're confident about input validity
  2. Error-aware API: Methods ending with 'E' return errors for better error handling
package main

import (
	"log"

	"github.com/AyakuraYuki/granges"
)

func main() {
	// Simple API - may return invalid ranges
	r1 := granges.Open(10, 5) // Invalid range, but no error returned
	if r1.IsInvalid() {
		log.Println("Invalid range detected")
	}

	// Error-aware API - explicit error handling
	r2, err := granges.OpenE(10, 5)
	if err != nil {
		log.Printf("Failed to create range: %v", err)
		return
	}
}

Working with Different Types

package main

import (
	"fmt"

	"github.com/AyakuraYuki/granges"
)

func main() {
	// Integer ranges
	intRange := granges.Closed(1, 100)

	// Float ranges
	floatRange := granges.Open(0.0, 1.0)
	fmt.Println(floatRange.Contains(0.5)) // true

	// String ranges (lexicographic ordering)
	stringRange := granges.Closed("apple", "orange")
	fmt.Println(stringRange.Contains("banana")) // true
	fmt.Println(stringRange.Contains("zebra"))  // false
}

Advanced Examples

Range Validation
package main

import "github.com/AyakuraYuki/granges"

func validateScore(score int) bool {
	validRange := granges.Closed(0, 100)
	return validRange.Contains(score)
}

Range Partitioning
package main

import "github.com/AyakuraYuki/granges"

func categorizeAge(age int) string {
	child := granges.ClosedOpen(0, 13)
	teen := granges.ClosedOpen(13, 20)
	adult := granges.ClosedOpen(20, 65)
	senior := granges.AtLeast(65)

	switch {
	case child.Contains(age):
		return "child"
	case teen.Contains(age):
		return "teenager"
	case adult.Contains(age):
		return "adult"
	case senior.Contains(age):
		return "senior"
	default:
		return "invalid"
	}
}

Range Merging
package main

import "github.com/AyakuraYuki/granges"

func mergeOverlappingRanges(r1, r2 granges.Range[int]) (granges.Range[int], bool) {
	if r1.IsConnected(r2) {
		return r1.Span(r2), true
	}
	return granges.Invalid[int](), false // Return invalid range if not connected
}

Thread Safety

All range operations are safe for concurrent use. Ranges are immutable after creation, so they can be safely shared between goroutines without additional synchronization.

package main

import (
	"fmt"

	"github.com/AyakuraYuki/granges"
)

var sharedRange = granges.Closed(1, 100)

func worker(id int) {
	// Safe to use sharedRange concurrently
	if sharedRange.Contains(id) {
		fmt.Printf("Worker %d is in range\n", id)
	}
}

Performance Considerations

  • Range creation and operations are generally O(1)
  • All ranges are lightweight value types
  • No heap allocations for basic operations
  • Comparable type constraints ensure efficient comparisons

Best Practices

  1. Use appropriate range types: Choose the most restrictive range type that fits your needs
  2. Validate inputs: Use error-returning variants (*E methods) when dealing with user input
  3. Prefer immutable patterns: Create new ranges instead of trying to modify existing ones
  4. Check connectivity: Use IsConnected() before performing intersection operations
  5. Handle edge cases: Be aware of empty ranges and unbounded ranges in your logic

Error Types

The library defines several error types:

  • ErrRangeSideUnbounded: Returned when trying to access endpoints of unbounded ranges
  • ErrUnboundedCut: Returned when trying to get bound types of unbounded ranges
  • ErrWrongBoundType: Returned when invalid bound types are provided

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

This library is ported from Google Guava's Range implementation. Special thanks to the Guava team for the excellent design and comprehensive functionality that inspired this Go version.

Documentation

Overview

Package granges implements a mathematical interval operation tool.

A range (or "interval") defines the boundaries around a contiguous span of values of some Comparable type; for example, "integers from 1 to 100 inclusive".

Types of ranges

Each end of the range may be bounded or unbounded. If bounded, there is an associated endpoint value, and the range is considered to be either OPEN (does not include the endpoint) or CLOSED (includes the endpoint) on that side. With three possibilities on each side, this yields nine basic types of ranges, enumerated below. (Notation: a square bracket ([]) indicates that the range is CLOSED on that side; a parenthesis (()) means it is either open or unbounded. The construct {x | statement} is read "the set of all x such that statement."

Range Types

  • Open: (a..b) -> {x | a < x < b}
  • Closed: [a..b] -> {x | a <= x <= b}
  • OpenClosed: (a..b] -> {x | a < x <= b}
  • ClosedOpen: [a..b) -> {x | a <= x < b}
  • GreaterThan: (a..+∞) -> {x | x > a}
  • AtLeast: [a..+∞) -> {x | x >= a}
  • LessThan: (-∞..b) -> {x | x < b}
  • AtMost: (-∞..b] -> {x | x <= b}
  • All: (-∞..+∞) -> {x}

When both endpoints exist, the upper endpoint may not be less than the lower. The endpoints may be equal only if at least one of the bounds is closed:

  • [a..a] : a singleton range
  • [a..a); (a..a] : empty ranges; also valid
  • (a..a) : invalid; an exception will be thrown

Warnings

  • Use immutable value types only, if at all possible. If you must use a mutable type, do not allow the endpoint instances to mutate after the range is created!
  • Your value type's comparison method should be consistent with equals if at all possible. Otherwise, be aware that concepts used throughout this documentation such as "equal", "same", "unique" and so on actually refer to whether Compare returns zero, not whether equals returns true.

Other notes

  • All ranges are shallow-immutable.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRangeSideUnbounded = errors.New("range unbounded on this side")
	ErrUnboundedCut       = errors.New("unbounded cut")
	ErrWrongBoundType     = errors.New("unknown bound type")
)

Functions

This section is empty.

Types

type BoundType

type BoundType int

BoundType indicates whether an endpoint of some range is contained in the range itself ("closed") or not ("open"). If a range is unbounded on a side, it is neither open nor closed on that side; the bound simply does not exist.

const (
	OPEN   BoundType = iota // open interval: ()
	CLOSED                  // closed interval: []
)
const Unbounded BoundType = -1

type Comparable

type Comparable interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 |
		~float32 | ~float64 | ~string
}

type Cut

type Cut[C Comparable] struct {
	// contains filtered or unexported fields
}

Cut is the implementation detail for the internal structure of Range instances. Represents a unique way of "cutting" a "number line" (actually of instances of type C, not necessarily "numbers") into two sections; this can be done below a certain value, above a certain value, below all values or above all values. With this object defined in this way, an interval can always be represented by a pair of Cut instances.

func NewAboveAll

func NewAboveAll[C Comparable]() Cut[C]

func NewAboveValue

func NewAboveValue[C Comparable](value C) Cut[C]

func NewBelowAll

func NewBelowAll[C Comparable]() Cut[C]

func NewBelowValue

func NewBelowValue[C Comparable](value C) Cut[C]

func (Cut[C]) Compare

func (c Cut[C]) Compare(other Cut[C]) int

func (Cut[C]) DescribeAsLowerBound

func (c Cut[C]) DescribeAsLowerBound() string

func (Cut[C]) DescribeAsUpperBound

func (c Cut[C]) DescribeAsUpperBound() string

func (Cut[C]) Endpoint

func (c Cut[C]) Endpoint() (endpoint C, err error)

func (Cut[C]) Equal

func (c Cut[C]) Equal(other Cut[C]) bool

func (Cut[C]) IsLessThan

func (c Cut[C]) IsLessThan(value C) bool

func (Cut[C]) TypeAsLowerBound

func (c Cut[C]) TypeAsLowerBound() (BoundType, error)

func (Cut[C]) TypeAsUpperBound

func (c Cut[C]) TypeAsUpperBound() (BoundType, error)

type CutType

type CutType int
const (
	BelowAll   CutType = iota // -∞
	AboveAll                  // +∞
	BelowValue                // <= value
	AboveValue                // > value
)

type Range

type Range[C Comparable] struct {
	// contains filtered or unexported fields
}

func All

func All[C Comparable]() Range[C]

All returns a range that contains every value of type T.

(-∞..+∞) = {x}

func AtLeast

func AtLeast[C Comparable](lower C) Range[C]

AtLeast returns a range that contains all values greater than or equal to endpoint.

[lower..+∞) = {x | lower <= x}

func AtMost

func AtMost[C Comparable](upper C) Range[C]

AtMost returns a range that contains all values less than or equal to endpoint.

(-∞..upper] = {x | x <= upper}

func Closed

func Closed[C Comparable](lower, upper C) Range[C]

Closed returns a range that contains all values greater than or equal to lower and less than or equal to upper.

[lower..upper] = {x | lower <= x <= upper}

An invalid range will be returned if lower is greater than upper.

func ClosedE

func ClosedE[C Comparable](lower, upper C) (Range[C], error)

ClosedE returns a range that contains all values greater than or equal to lower and less than or equal to upper.

[lower..upper] = {x | lower <= x <= upper}

An invalid range with an error will be returned if lower is greater than upper.

func ClosedOpen

func ClosedOpen[C Comparable](lower, upper C) Range[C]

ClosedOpen returns a range that contains all values greater than or equal to lower and strictly less than upper.

[lower..upper) = {x | lower <= x < upper}

An invalid range will be returned if lower is greater than upper.

func ClosedOpenE

func ClosedOpenE[C Comparable](lower, upper C) (Range[C], error)

ClosedOpenE returns a range that contains all values greater than or equal to lower and strictly less than upper.

[lower..upper) = {x | lower <= x < upper}

An invalid range with an error will be returned if lower is greater than upper.

func DownTo

func DownTo[C Comparable](endpoint C, boundType BoundType) (Range[C], error)

DownTo returns a range from the given endpoint, which may be either inclusive (closed) or exclusive (open), with no upper bound. An empty range with an error will be return if wrong arguments received.

func GreaterThan

func GreaterThan[C Comparable](lower C) Range[C]

GreaterThan returns a range that contains all values strictly greater than endpoint.

(lower..+∞) = {x | lower < x}

func Invalid added in v1.0.1

func Invalid[C Comparable]() Range[C]

Invalid creates an explicitly invalid range of the specified comparable type.

This method is useful when you need to represent the concept of "no valid range" or signal an error condition in contexts where returning a range is required but no meaningful range can be constructed.

func LessThan

func LessThan[C Comparable](upper C) Range[C]

LessThan returns a range that contains all values strictly less than endpoint.

(-∞..upper) = {x | x < upper}

func New

func New[C Comparable](lower C, lowerType BoundType, upper C, upperType BoundType) Range[C]

New returns a range that contains any value from lower to upper, where each endpoint may be either inclusive (closed) or exclusive (open).

An invalid range will be returned if lower is greater than upper.

func NewE

func NewE[C Comparable](lower C, lowerType BoundType, upper C, upperType BoundType) (Range[C], error)

NewE returns a range that contains any value from lower to upper, where each endpoint may be either inclusive (closed) or exclusive (open).

An invalid range with an error will be returned if lower is greater than upper.

func Open

func Open[C Comparable](lower, upper C) Range[C]

Open returns a range that contains all values strictly greater than lower and strictly less than upper.

(lower..upper) = {x | lower < x < upper}

An invalid range will be returned if lower is greater than or equal to upper.

func OpenClosed

func OpenClosed[C Comparable](lower, upper C) Range[C]

OpenClosed returns a range that contains all values strictly greater than lower and less than or equal to upper.

(lower..upper] = {x | lower < x <= upper}

An invalid range will be returned if lower is greater than upper.

func OpenClosedE

func OpenClosedE[C Comparable](lower, upper C) (Range[C], error)

OpenClosedE returns a range that contains all values strictly greater than lower and less than or equal to upper.

(lower..upper] = {x | lower < x <= upper}

An invalid range with an error will be returned if lower is greater than upper.

func OpenE

func OpenE[C Comparable](lower, upper C) (Range[C], error)

OpenE returns a range that contains all values strictly greater than lower and strictly less than upper.

(lower..upper) = {x | lower < x < upper}

An invalid range with an error will be returned if lower is greater than or equal to upper.

func Singleton

func Singleton[C Comparable](value C) Range[C]

Singleton returns a Range that contains only the given value. The returned range is CLOSED on both ends.

(x) = {x}

func UpTo

func UpTo[C Comparable](endpoint C, boundType BoundType) (Range[C], error)

UpTo returns a range with no lower bound up to the given endpoint, which may be either inclusive (closed) or exclusive (open). An empty range with an error will be return if wrong arguments received.

func (Range[C]) Contains

func (r Range[C]) Contains(value C) bool

Contains returns true if value is within the bounds of this range. For example, on the range [0..2), Contains(1) returns true, while Contains(2) returns false.

func (Range[C]) ContainsAll

func (r Range[C]) ContainsAll(values []C) bool

ContainsAll returns true if every element in values is contained in this range.

func (Range[C]) Encloses

func (r Range[C]) Encloses(other Range[C]) bool

Encloses returns true if the bounds of other do not extend outside the bounds of this range.

Examples:

  • [3..6] encloses [4..5]
  • (3..6) encloses (3..6)
  • [3..6] encloses [4..4) (even though the latter is empty)
  • (3..6] does not enclose [3..6]
  • [4..5] does not enclose (3..6) (even though it contains every value contained by the latter range)
  • [3..6] does not enclose (1..1] (even though it contains every value contained by the latter range)

Note that if a.Encloses(b), then b.Contains(v) implies a.Contains(v), but as the last two examples illustrate, the converse is not always true.

Being reflexive, antisymmetric and transitive, the encloses relation defines a partial order over ranges. There exists a unique maximal range according to this relation, and also numerous minimal ranges. Enclosure also implies connectedness.

func (Range[C]) Equal

func (r Range[C]) Equal(other Range[C]) bool

Equal returns true if object is a range having the same endpoints and bound types as this range. Note that discrete ranges such as (1..4) and [2..3] are not equal to one another, despite the fact that they each contain precisely the same set of values. Similarly, empty ranges are not equal unless they have exactly the same representation, so [3..3), (3..3], (4..4] are all unequal.

func (Range[C]) Gap

func (r Range[C]) Gap(other Range[C]) Range[C]

Gap returns the maximal range lying between this range and otherRange, if such a range exists. The resulting range may be empty if the two ranges are adjacent but non-overlapping.

An invalid range will be returned if this range and otherRange have a nonempty intersection.

func (Range[C]) GapE

func (r Range[C]) GapE(other Range[C]) (Range[C], error)

GapE returns the maximal range lying between this range and otherRange, if such a range exists. The resulting range may be empty if the two ranges are adjacent but non-overlapping.

For example, the gap of [1..5] and (7..10) is (5..7]. The resulting range may be empty; for example, the gap between [1..5) [5..7) yields the empty range [5..5).

The gap exists if and only if the two ranges are either disconnected or immediately adjacent (any intersection must be an empty range).

The gap operation is commutative.

An error will be returned if this range and otherRange have a nonempty intersection.

func (Range[C]) HasLowerBound

func (r Range[C]) HasLowerBound() bool

HasLowerBound returns true if this range has a lower endpoint.

func (Range[C]) HasUpperBound

func (r Range[C]) HasUpperBound() bool

HasUpperBound returns true if this range has an upper endpoint.

func (Range[C]) Intersection

func (r Range[C]) Intersection(connectedRange Range[C]) Range[C]

Intersection returns the maximal range enclosed by both this range and connectedRange, if such a range exists.

An invalid range will be returned for disconnected ranges.

func (Range[C]) IntersectionE

func (r Range[C]) IntersectionE(connectedRange Range[C]) (Range[C], error)

IntersectionE returns the maximal range enclosed by both this range and connectedRange, if such a range exists.

For example, the intersection of [1..5] and (3..7) is (3..5]. The resulting range may be empty; for example, [1..5) intersected with [5..7) yields the empty range [5..5).

The intersection exists if and only if the two ranges are connected.

The intersection operation is commutative, associative and idempotent, and its identity element is All.

An error will be returned for disconnected ranges.

func (Range[C]) IsConnected

func (r Range[C]) IsConnected(other Range[C]) bool

IsConnected returns true if there exists a (possibly empty) range which is enclosed by both this range and other.

For example,

  • [2, 4) and [5, 7) are not connected
  • [2, 4) and [3, 5) are connected, because both enclose [3, 4)
  • [2, 4) and [4, 6) are connected, because both enclose the empty range [4, 4)

Note that this range and other have a well-defined union and intersection (as a single, possibly-empty range) if and only if this method returns true.

The connectedness relation is both reflexive and symmetric, but does not form an equivalence relation as it is not transitive.

func (Range[C]) IsEmpty

func (r Range[C]) IsEmpty() bool

IsEmpty returns true if this range is of the form [v..v) or (v..v]. (This does not encompass ranges of the form (v..v), because such ranges are invalid and can't be constructed at all.)

func (Range[C]) IsInvalid

func (r Range[C]) IsInvalid() bool

IsInvalid identifies the range is invalid or not

func (Range[C]) LowerBoundType

func (r Range[C]) LowerBoundType() BoundType

LowerBoundType returns the type of this range's lower bound: CLOSED if the range includes its lower endpoint, OPEN if it does not, Unbounded if this range is unbounded below (that is, HasLowerBound returns false).

func (Range[C]) LowerBoundTypeE

func (r Range[C]) LowerBoundTypeE() (BoundType, error)

LowerBoundTypeE returns the type of this range's lower bound: CLOSED if the range includes its lower endpoint, OPEN if it does not, Unbounded and ErrUnboundedCut error if this range is unbounded below (that is, HasLowerBound returns false).

func (Range[C]) LowerEndpoint

func (r Range[C]) LowerEndpoint() C

LowerEndpoint returns the lower endpoint of this range with ignoring ErrRangeSideUnbounded error.

func (Range[C]) LowerEndpointE

func (r Range[C]) LowerEndpointE() (C, error)

LowerEndpointE returns the lower endpoint of this range. If this range is unbounded below (that is, HasLowerBound returns false), the ErrRangeSideUnbounded will be returned.

func (Range[C]) Span

func (r Range[C]) Span(other Range[C]) Range[C]

Span returns the minimal range that encloses both this range and other. For example, the span of [1..3] and (5..7) is [1..7).

An invalid range will be returned if failed to create new range.

func (Range[C]) SpanE

func (r Range[C]) SpanE(other Range[C]) (Range[C], error)

SpanE returns the minimal range that encloses both this range and other. For example, the span of [1..3] and (5..7) is [1..7).

If the input ranges are connected, the returned range can also be called their union. If they are not, note that the span might contain values that are not contained in either input range.

Like intersection, this operation is commutative, associative and idempotent. Unlike it, it is always well-defined for any two input ranges.

An error will be returned if failed to create new range.

func (Range[C]) String

func (r Range[C]) String() string

func (Range[C]) UpperBoundType

func (r Range[C]) UpperBoundType() BoundType

UpperBoundType returns the type of this range's upper bound: CLOSED if the range includes its upper endpoint, OPEN if it does not, Unbounded if this range is unbounded above (that is, HasUpperBound returns false).

func (Range[C]) UpperBoundTypeE

func (r Range[C]) UpperBoundTypeE() (BoundType, error)

UpperBoundTypeE returns the type of this range's upper bound: CLOSED if the range includes its upper endpoint, OPEN if it does not, Unbounded and ErrUnboundedCut error if this range is unbounded above (that is, HasUpperBound returns false).

func (Range[C]) UpperEndpoint

func (r Range[C]) UpperEndpoint() C

UpperEndpoint returns the upper endpoint of this range with ignoring ErrRangeSideUnbounded error.

func (Range[C]) UpperEndpointE

func (r Range[C]) UpperEndpointE() (C, error)

UpperEndpointE returns the lower endpoint of this range. If this range is unbounded above (that is, HasUpperBound returns false), the ErrRangeSideUnbounded will be returned.

Jump to

Keyboard shortcuts

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