Intervals - craterdog/go-component-framework GitHub Wiki

Overview

A interval is an implicit sequence that captures a finite range of discrete element values. The endpoints in the interval may be inclusive or exclusive. Because an interval contains a finite number of element values it can be interated over.

UML Diagram

A Quick Example

To whet your appetite, here is some short example code that demonstrates the use of intervals.

package main

import (
	fmt "fmt"
	fra "github.com/craterdog/go-component-framework/v7"
)

func main() {
	// Create some duration intervals using the module constructor shortcut.
	var durations = fra.IntervalClass[fra.DurationLike]().Interval(
		fra.Exclusive,
		fra.DurationFromString("~P0W"),
		fra.DurationFromString("~P4W"),
		fra.Inclusive,
	)
	fmt.Println(durations)
	durations = fra.Interval[fra.DurationLike](
		fra.Inclusive,
		fra.DurationFromString("~P5D"),
		fra.DurationClass().Undefined(),
		fra.Exclusive,
	)
	fmt.Println(durations)

	// Create a moment interval using the module constructor shortcut.
	var moments = fra.Interval[fra.MomentLike](
		fra.Exclusive,
		fra.MomentFromString("<2001-02-03T04:05:06>"),
		fra.MomentFromString("<2001-02-03T04:05:07>"),
		fra.Exclusive,
	)
	fmt.Println(moments)

	// Create a glyph interval using the module constructor shortcut.
	var glyphs = fra.Interval[fra.GlyphLike](
		fra.Inclusive,
		fra.Glyph(65),
		fra.Glyph(70),
		fra.Inclusive,
	)
	fmt.Println(glyphs)

	// Iterate through the glyphs in the interval.
	var iterator = glyphs.GetIterator()
	for iterator.HasNext() {
		var glyph = iterator.GetNext()
		fmt.Println(glyph)
	}
}

Try it out in the Go Playground...