Spectrums - craterdog/go-component-framework GitHub Wiki

Overview

A spectrum is an implicit sequence that captures an infinite range of discrete string values. The endpoints in the spectrum may be inclusive or exclusive. Because a spectrum contains an infinite number of string values it cannot be interated over.

UML Diagram

A Quick Example

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

package main

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

func main() {
	// Create some number spectrums using the module constructor shortcut.
	var names = fra.Spectrum[fra.NameLike](
		fra.Inclusive,
		fra.NameFromString("/nebula/classes/abstract"),
		fra.NameFromString("/nebula/types"),
		fra.Inclusive,
	)
	fmt.Println(names)

	var quotes = fra.SpectrumClass[fra.QuoteLike]().Spectrum(
		fra.Inclusive,
		fra.QuoteFromString(`"A"`),
		fra.QuoteFromString(`"Fe"`),
		fra.Exclusive,
	)
	fmt.Println(quotes)

	var versions = fra.Spectrum[fra.VersionLike](
		fra.Exclusive,
		fra.VersionFromString("v1.2.3"),
		fra.VersionFromString("v2"),
		fra.Exclusive,
	)
	fmt.Println(versions)
}

Try it out in the Go Playground...