value

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2026 License: MIT Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package value provides immutable, language-neutral refinement values.

Index

Constants

View Source
const LeapTableVersion = "IERS-C72-2026-07-06"

The dates are facts from the IERS leap-second table, Bulletin C 72 (2026-07-06). The bulletin confirms no December 2026 leap. Future possible leap labels are unknown instead of relying on a live fetch or silently accepting speculation. Sources: https://hpiers.obspm.fr/iers/bul/bulc/Leap_Second.dat

https://hpiers.obspm.fr/iers/bul/bulc/bulletinc.dat

Variables

This section is empty.

Functions

func DataKindEqual

func DataKindEqual(a, b DataKind) bool

DataKindEqual reports structural equality of a and b.

func DataKindEqualWith

func DataKindEqualWith(a, b DataKind, ov DataKindEqOverrides) bool

DataKindEqualWith reports structural equality of a and b under ov.

func Fold

func Fold[R any](d DataKind, cs DataKindCases[R]) R

Fold reduces DataKind by one-level case analysis.

Types

type BoolData

type BoolData struct{}

type Data

type Data struct {
	// contains filtered or unexported fields
}

Data is an immutable, function-free payload tree. It does not assert that a schema's structure or refinements have been validated. Nominal type identity belongs to the checked contract; wrappers do not change this raw payload. Its zero value is the explicit Null constructor, never an absent field.

func List

func List(items []Data) Data

func Map

func Map(entries []MapEntry) (Data, error)

Map constructs an immutable string-keyed map. Entry order has no semantic meaning: construction sorts by exact UTF-16 code units. Escape spelling is already decoded by Text, while case and Unicode normalization remain exact.

func OfBool

func OfBool(b bool) Data

func OfNumber

func OfNumber(n Number) Data

func OfText

func OfText(t Text) Data

func Record

func Record(fields []DataField) (Data, error)

Record field order is retained. Duplicate names are an error, even if their values agree. Native escaped UTF-16 object keys remain in schemajson.Node; these are checked-language field identifiers, not a native JSON AST.

func Variant

func Variant(name string, args []Data) (Data, error)

Variant distinguishes Nothing/Just, Null/NonNull, Err/Ok, and user-defined alternatives. Constructor names/arity are checked against the contract later.

func (Data) Boolean

func (d Data) Boolean() (bool, bool)

func (Data) Constructor

func (d Data) Constructor() (string, bool)

func (Data) Elements

func (d Data) Elements() []Data

func (Data) Entries

func (d Data) Entries() []MapEntry

func (Data) EqualWith

func (d Data) EqualWith(other Data, step func(uint64) error) (bool, error)

EqualWith is structural equality, with explicit work charging. Record order does not affect equality; list/constructor argument order does. The callback is called before each compared node and each scalar code unit/digit. The iterative traversal is safe for trees deeper than the Go call stack.

func (Data) Fields

func (d Data) Fields() []DataField

func (Data) Kind

func (d Data) Kind() DataKind

func (Data) Lookup

func (d Data) Lookup(name string) (Data, bool)

func (Data) LookupKey

func (d Data) LookupKey(key Text) (Data, bool)

func (Data) Number

func (d Data) Number() (Number, bool)

func (Data) ReplaceFields

func (d Data) ReplaceFields(changes []DataField) (Data, error)

ReplaceFields applies all changes to an existing record in one immutable transformation. It does not validate refinements: the validating update layer must validate the completed candidate once, never intermediate field states. Missing targets and duplicate edits fail without modifying any input.

func (Data) Size

func (d Data) Size() int

Size returns the immediate element/argument/field count without allocating.

func (Data) Text

func (d Data) Text() (Text, bool)

type DataField

type DataField struct {
	Name  string
	Value Data
}

type DataKind

type DataKind interface {
	// contains filtered or unexported methods
}

type DataKindCases

type DataKindCases[R any] struct {
	NumberData  func() R
	TextData    func() R
	BoolData    func() R
	ListData    func() R
	RecordData  func() R
	VariantData func() R
	MapData     func() R
}

DataKindCases selects one handler per DataKind variant for Fold.

type DataKindEqOverrides

type DataKindEqOverrides struct {
	NumberData  func(x, y NumberData) (eq, handled bool)
	TextData    func(x, y TextData) (eq, handled bool)
	BoolData    func(x, y BoolData) (eq, handled bool)
	ListData    func(x, y ListData) (eq, handled bool)
	RecordData  func(x, y RecordData) (eq, handled bool)
	VariantData func(x, y VariantData) (eq, handled bool)
	MapData     func(x, y MapData) (eq, handled bool)
}

DataKindEqOverrides carries optional per-variant hooks for DataKindEqualWith. A hook returning handled=false falls through to the derived comparison.

type ListData

type ListData struct{}

type MapData

type MapData struct{}

type MapEntry

type MapEntry struct {
	Key   Text
	Value Data
}

type Number

type Number struct {
	// contains filtered or unexported fields
}

Number is an immutable exact rational. Its zero value is zero. No mutable math/big object is exposed or shared between arithmetic operations.

func Integer

func Integer(n int64) Number

func ParseNumber

func ParseNumber(text string) (Number, error)

ParseNumber accepts decimal integers/fractions/exponents or a rational n/d. Errors deliberately omit input values. Callers must budget input size before parsing; this value primitive does not own a validation execution budget.

func (Number) Add

func (n Number) Add(other Number) Number

func (Number) Ceiling

func (n Number) Ceiling() Number

func (Number) Compare

func (n Number) Compare(other Number) int

func (Number) Decimal

func (n Number) Decimal() (string, error)

Decimal returns an exact finite decimal for wire encodings which support it. Nonterminating fractions fail instead of silently rounding (e.g. 1/3).

func (Number) Divide

func (n Number) Divide(other Number) (Number, error)

func (Number) ExactFloat32

func (n Number) ExactFloat32() (Number, error)

ExactFloat32 and ExactFloat64 admit only finite IEEE-754 values whose mathematical value is exactly n. They do not convert through a host float, so their result is deterministic and retains the exact rational value.

func (Number) ExactFloat64

func (n Number) ExactFloat64() (Number, error)

func (Number) FixedWidth

func (n Number) FixedWidth(bits uint, signed bool) (Number, error)

FixedWidth rejects values outside the explicitly requested integer type. The returned value is unchanged. Wrapping must use Wrap explicitly.

func (Number) Floor

func (n Number) Floor() Number

func (Number) IsInteger

func (n Number) IsInteger() bool

func (Number) Multiply

func (n Number) Multiply(other Number) Number

func (Number) Negate

func (n Number) Negate() Number

func (Number) Remainder

func (n Number) Remainder(other Number) (Number, error)

Remainder uses a quotient truncated toward zero; a nonzero remainder has the dividend's sign. It is integer-only and never rounds a fractional operand.

func (Number) RoundFloat32

func (n Number) RoundFloat32() (Number, error)

RoundFloat32 and RoundFloat64 explicitly round to the nearest finite IEEE value, resolving ties toward an even significand. A result which would be an infinity is rejected. IEEE signed zero has no distinct language identity.

func (Number) RoundFloat64

func (n Number) RoundFloat64() (Number, error)

func (Number) RoundHalfEven

func (n Number) RoundHalfEven() Number

func (Number) Show

func (n Number) Show() string

Show is canonical: reduced fractions have positive denominators; whole numbers have no denominator. The payload is never rounded or normalized in place; all Number instances are immutable mathematical values.

func (Number) Sign

func (n Number) Sign() int

func (Number) Subtract

func (n Number) Subtract(other Number) Number

func (Number) Truncate

func (n Number) Truncate() Number

Truncate, Floor, Ceiling and RoundHalfEven are explicit exact-to-integer rounding operations. They return new values and never modify the payload.

func (Number) Wrap

func (n Number) Wrap(bits uint, signed bool) (Number, error)

type NumberData

type NumberData struct{}

type RecordData

type RecordData struct{}

type Text

type Text struct {
	// contains filtered or unexported fields
}

Text stores the exact UTF-16 sequence, including unpaired surrogate code units. Conversion to a Unicode-scalar wire encoding is explicitly fallible; it must never replace a code unit with U+FFFD silently.

func ReadText

func ReadText(input string) (Text, error)

ReadText accepts quoted text and JSON-style escapes, retaining each escaped UTF-16 unit exactly. Invalid UTF-8, controls, and malformed escapes fail.

func TextFromUTF8

func TextFromUTF8(text string) (Text, error)

func TextFromUnits

func TextFromUnits(units []uint16) Text

func (Text) CodePointLength

func (t Text) CodePointLength() int

CodePointLength counts valid UTF-16 surrogate pairs as one code point and every other code unit, including an unmatched surrogate, as one. It does not normalize text and matches Java String.codePointCount semantics.

func (Text) Compare

func (t Text) Compare(other Text) int

Compare returns exact UTF-16 code-unit order without allocating or applying Unicode normalization. It is the canonical order for typed map keys.

func (Text) Concat

func (t Text) Concat(other Text) Text

func (Text) Equal

func (t Text) Equal(other Text) bool

func (Text) Length

func (t Text) Length() int

func (Text) Show

func (t Text) Show() string

Show uses a deterministic ASCII quoted representation. Printable ASCII is literal except quote/backslash; every other UTF-16 unit uses lowercase \uXXXX. The canonical read/show codec is independent of any selected serde format.

func (Text) UTF8

func (t Text) UTF8() (string, error)

func (Text) Units

func (t Text) Units() []uint16

type TextData

type TextData struct{}

type Timestamp

type Timestamp struct {
	// contains filtered or unexported fields
}

Timestamp preserves the RFC 3339 payload spelling, numeric offset and exact fraction. Calendar work uses only UTC; no clock, locale, zone database or I/O participates. The zero value is the Unix epoch, not the current time.

func ParseTimestamp

func ParseTimestamp(raw string) (Timestamp, error)

ParseTimestamp accepts the RFC 3339 profile, including lower-case t/z, unbounded decimal fractional precision, numeric offsets and known leap labels. As with Number parsing, the caller must budget input size before this primitive.

func (Timestamp) CivilSecondsUntil

func (t Timestamp) CivilSecondsUntil(other Timestamp) (Number, error)

CivilSecondsUntil is explicit civil-coordinate arithmetic, not an assertion about elapsed SI seconds. It excludes inserted leap seconds between endpoints and refuses a leap-labelled endpoint, which has no unique ordinary coordinate.

func (Timestamp) Compare

func (t Timestamp) Compare(other Timestamp) int

Compare orders UTC instants, distinguishing a leap second from the following midnight. Offset spelling and decimal precision do not alter instant equality. -00:00 denotes a known UTC instant with unknown local offset, per RFC 3339 §4.3.

func (Timestamp) Equal

func (t Timestamp) Equal(other Timestamp) bool

func (Timestamp) Fraction

func (t Timestamp) Fraction() Number

func (Timestamp) LeapSecond

func (t Timestamp) LeapSecond() bool

func (Timestamp) OffsetKnown

func (t Timestamp) OffsetKnown() bool

func (Timestamp) OffsetMinutes

func (t Timestamp) OffsetMinutes() int

func (Timestamp) Raw

func (t Timestamp) Raw() string

func (Timestamp) SISecondsUntil

func (t Timestamp) SISecondsUntil(other Timestamp) (Number, error)

SISecondsUntil includes leap seconds in the pinned history. Outside the post-1972, announced interval, a physical elapsed duration is unknown; civil coordinate arithmetic remains available under its explicit name above.

func (Timestamp) Show

func (t Timestamp) Show() string

Show quotes the retained RFC 3339 representation. This preserves offset metadata and original precision across canonical read/show, without rounding.

type TimestampError

type TimestampError struct {
	Code    string
	Message string
}

func (*TimestampError) Error

func (e *TimestampError) Error() string

type VariantData

type VariantData struct{}

Jump to

Keyboard shortcuts

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