value

package
v0.0.0-...-ced9a64 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package value is the FEEL/DMN runtime value model: the Value interface and its concrete kinds (null, boolean, number, string, the temporal types, list, context, range and function), together with equality, ordering and arithmetic that follow FEEL semantics — most importantly decimal numbers (never float64, ADR-0007) and pervasive null propagation.

It is a foundational package imported by the FEEL compiler, the boxed expression and decision-table engines and the public API. It lives apart from package feel so that value names such as Number and Kind do not collide with the lexer's token kinds.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compare

func Compare(a, b Value) (int, bool)

Compare orders two values for the relational operators (<, <=, >, >=). It returns -1, 0 or +1 and ok=true when the values are comparable; ok is false when either is null or the kinds have no defined ordering, in which case the relational operator yields null.

func IsNull

func IsNull(v Value) bool

IsNull reports whether v is the FEEL null (or a Go nil Value).

Types

type Bool

type Bool bool

Bool is a FEEL boolean.

func (Bool) Kind

func (Bool) Kind() Kind

Kind returns KindBool.

func (Bool) String

func (b Bool) String() string

type Context

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

Context is an ordered key→value map. Iteration follows insertion order; two contexts are equal when they hold the same entries regardless of order.

func NewContext

func NewContext() *Context

NewContext returns an empty context.

func (*Context) Get

func (c *Context) Get(key string) (Value, bool)

Get returns the value for key and whether it is present.

func (*Context) Keys

func (c *Context) Keys() []string

Keys returns the keys in insertion order.

func (*Context) Kind

func (*Context) Kind() Kind

Kind returns KindContext.

func (*Context) Len

func (c *Context) Len() int

Len returns the number of entries.

func (*Context) Put

func (c *Context) Put(key string, v Value) *Context

Put sets key to v, preserving insertion order for new keys, and returns c.

func (*Context) String

func (c *Context) String() string

type Date

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

Date is a calendar date with no time-of-day or zone. It is stored as midnight UTC for the given day.

func DateFromComponents

func DateFromComponents(year, month, day int) Date

DateFromComponents builds a Date from year, month and day.

func NewDate

func NewDate(year int, month time.Month, day int) Date

NewDate builds a Date from year, month, day.

func ParseDate

func ParseDate(s string) (Date, error)

ParseDate parses an ISO date "YYYY-MM-DD", including negative (BCE) years.

func (Date) Kind

func (Date) Kind() Kind

Kind returns KindDate.

func (Date) String

func (d Date) String() string

func (Date) Time

func (d Date) Time() time.Time

Time returns the underlying instant (midnight UTC).

type DateTime

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

DateTime is a date and time, optionally with a zone.

func CombineDateTime

func CombineDateTime(d Date, t Time) DateTime

CombineDateTime merges a date with a time-of-day into a date-and-time, taking the zone from the time component.

func NewDateTime

func NewDateTime(t time.Time) DateTime

NewDateTime returns a zoned DateTime for the instant t. The location of t determines the rendered zone suffix (UTC renders as "Z"). It is the entry point used when converting a Go time.Time input into a FEEL value.

func ParseDateTime

func ParseDateTime(s string) (DateTime, error)

ParseDateTime parses "YYYY-MM-DDTHH:MM:SS(.fff)?" with an optional zone suffix.

func (DateTime) Kind

func (DateTime) Kind() Kind

Kind returns KindDateTime.

func (DateTime) String

func (dt DateTime) String() string

func (DateTime) Time

func (dt DateTime) Time() time.Time

Time returns the underlying instant.

type DaysTimeDuration

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

DaysTimeDuration is a duration measured in seconds/nanoseconds (may be negative). It cannot be converted to a YearsMonthsDuration.

func NewDaysTimeDuration

func NewDaysTimeDuration(d time.Duration) DaysTimeDuration

NewDaysTimeDuration builds a days-and-time duration from a time.Duration.

func (DaysTimeDuration) Duration

func (d DaysTimeDuration) Duration() time.Duration

Duration returns the duration as a time.Duration.

func (DaysTimeDuration) Kind

func (DaysTimeDuration) Kind() Kind

Kind returns KindDaysTimeDuration.

func (DaysTimeDuration) String

func (d DaysTimeDuration) String() string

type Function

type Function struct {
	Name  string
	Arity int
	Call  func(args []Value) (Value, error)
}

Function is a callable FEEL value (builtin or user-defined). The Call closure is wired up by the compiler (WP-06); the value model only carries it.

func (*Function) Kind

func (*Function) Kind() Kind

Kind returns KindFunction.

func (*Function) String

func (f *Function) String() string

type Kind

type Kind uint8

Kind identifies a FEEL value's type. The FEEL type system distinguishes two duration types that are not interconvertible (months vs. seconds).

const (
	KindNull Kind = iota
	KindBool
	KindNumber
	KindString
	KindDate
	KindTime
	KindDateTime
	KindDaysTimeDuration
	KindYearsMonthsDuration
	KindList
	KindContext
	KindRange
	KindFunction
)

FEEL value kinds.

func (Kind) String

func (k Kind) String() string

String returns the FEEL type name of the kind.

type List

type List struct {
	Elements []Value
}

List is an ordered FEEL list.

func NewList

func NewList(elems ...Value) List

NewList returns a List over the given elements.

func (List) Kind

func (List) Kind() Kind

Kind returns KindList.

func (List) String

func (l List) String() string

type Number

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

Number is a FEEL number backed by an arbitrary-precision decimal.

func MustNumber

func MustNumber(s string) Number

MustNumber parses s and panics on error; for tests and constants.

func NumberFromInt64

func NumberFromInt64(i int64) Number

NumberFromInt64 returns a Number for i.

func ParseNumber

func ParseNumber(s string) (Number, error)

ParseNumber parses a FEEL numeric literal (decimal, optional exponent; no hex/octal). It returns an error for malformed or non-finite input.

func (Number) Abs

func (n Number) Abs() Number

Abs returns the absolute value of n.

func (Number) Ceiling

func (n Number) Ceiling() Number

Ceiling returns the smallest integer greater than or equal to n.

func (Number) CeilingTo

func (n Number) CeilingTo(scale int32) (Number, bool)

CeilingTo rounds n up (toward +infinity) to scale digits after the decimal point, matching FEEL ceiling(n, scale).

func (Number) Cmp

func (n Number) Cmp(o Number) int

Cmp compares two numbers as -1, 0 or +1. Integer operands (the common case in decision-table range and equality tests) compare natively as int64, skipping the decimal alignment apd.Cmp performs; the result is identical.

func (Number) Decimal

func (n Number) Decimal() *apd.Decimal

Decimal returns the underlying decimal. Callers must not mutate it.

func (Number) Even

func (n Number) Even() (bool, bool)

Even reports whether n is an even integer. A non-integer yields ok=false.

func (Number) Exp

func (n Number) Exp() (Number, bool)

Exp returns e raised to the power n.

func (Number) Floor

func (n Number) Floor() Number

Floor returns the greatest integer less than or equal to n.

func (Number) FloorTo

func (n Number) FloorTo(scale int32) (Number, bool)

FloorTo rounds n down (toward -infinity) to scale digits after the decimal point, matching FEEL floor(n, scale).

func (Number) Int64

func (n Number) Int64() (int64, bool)

Int64 returns n truncated to an int64 and whether it fit exactly as an integer.

func (Number) IsInteger

func (n Number) IsInteger() bool

IsInteger reports whether n has no fractional part.

func (Number) IsZero

func (n Number) IsZero() bool

IsZero reports whether the number is zero.

func (Number) Kind

func (Number) Kind() Kind

Kind returns KindNumber.

func (Number) Ln

func (n Number) Ln() (Number, bool)

Ln returns the natural logarithm of n. A non-positive operand yields ok=false.

func (Number) Modulo

func (n Number) Modulo(o Number) (Number, bool)

Modulo returns the FEEL modulo of n by o, defined as n - o*floor(n/o) so the result takes the sign of the divisor. A zero divisor yields ok=false.

func (Number) Odd

func (n Number) Odd() (bool, bool)

Odd reports whether n is an odd integer. A non-integer yields ok=false.

func (Number) RoundDown

func (n Number) RoundDown(scale int32) (Number, bool)

RoundDown rounds n to scale digits toward zero (FEEL "round down", truncation).

func (Number) RoundHalfDown

func (n Number) RoundHalfDown(scale int32) (Number, bool)

RoundHalfDown rounds n to scale digits, ties toward zero (FEEL "round half down").

func (Number) RoundHalfEven

func (n Number) RoundHalfEven(scale int32) (Number, bool)

RoundHalfEven rounds n to scale digits after the decimal point using round-half-even, matching the FEEL decimal(n, scale) built-in.

func (Number) RoundHalfUp

func (n Number) RoundHalfUp(scale int32) (Number, bool)

RoundHalfUp rounds n to scale digits, ties away from zero (FEEL "round half up").

func (Number) RoundUp

func (n Number) RoundUp(scale int32) (Number, bool)

RoundUp rounds n to scale digits, away from zero on ties and otherwise toward the next magnitude (FEEL "round up").

func (Number) SecondsNanos

func (n Number) SecondsNanos() (sec int64, nanos int, ok bool)

SecondsNanos splits a non-negative second count into whole seconds and the remaining nanoseconds, for the time()/date and time() constructors, which accept a fractional second (e.g. time(12,59,1.3,…) → …01.3…). The fraction is rounded half-even to nanosecond precision. ok is false when n is negative or its whole-second part does not fit an int64.

func (Number) Sqrt

func (n Number) Sqrt() (Number, bool)

Sqrt returns the square root of n. A negative operand yields ok=false.

func (Number) String

func (n Number) String() string

String renders the number in plain (non-scientific) decimal form, which is the canonical FEEL string for typical magnitudes.

type Range

type Range struct {
	LowClosed  bool
	Low        Value
	High       Value
	HighClosed bool
}

Range is a FEEL range. Low or High may be Null to denote an unbounded end.

func (Range) Kind

func (Range) Kind() Kind

Kind returns KindRange.

func (Range) String

func (r Range) String() string

type Str

type Str string

Str is a FEEL string.

func (Str) Kind

func (Str) Kind() Kind

Kind returns KindString.

func (Str) String

func (s Str) String() string

type Time

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

Time is a time-of-day, optionally with a zone. The date part of the backing instant is a fixed reference day and is not significant.

func NewTime

func NewTime(hour, minute, second, nanos int, offset *DaysTimeDuration) Time

NewTime builds a time-of-day from components. When offset is non-nil the time is zoned at that fixed UTC offset; otherwise it is a local time without a zone.

func ParseTime

func ParseTime(s string) (Time, error)

ParseTime parses "HH:MM:SS(.fff)?" with an optional Z, ±HH:MM or @Zone suffix.

func TimeOf

func TimeOf(dt DateTime) Time

TimeOf extracts the time-of-day (with zone) from a date-and-time. Time and DateTime share an identical layout, so a direct conversion suffices.

func (Time) Kind

func (Time) Kind() Kind

Kind returns KindTime.

func (Time) String

func (t Time) String() string

type Value

type Value interface {
	Kind() Kind
	// String renders the value in its canonical FEEL form.
	String() string
	// contains filtered or unexported methods
}

Value is a FEEL runtime value. Implementations are immutable; operations return new values. The null value is represented by Null, never a Go nil, so callers can always call methods safely.

var (
	True  Value = Bool(true)
	False Value = Bool(false)
)

Shared boolean values.

var Null Value = nullValue{}

Null is the single FEEL null value. Most operations propagate it.

func Add

func Add(a, b Value) Value

Add implements `+`: numbers, like-typed durations, and date/time ± duration.

func BoolOf

func BoolOf(b bool) Value

BoolOf returns True or False for b.

func Div

func Div(a, b Value) Value

Div implements `/`: number/number, duration/number and duration/duration.

func Equal

func Equal(a, b Value) Value

Equal implements FEEL `=` semantics. It returns a Bool: two nulls are equal, a null and a non-null are not, and values of different kinds are not equal. Equality never yields null.

func Exp

func Exp(a, b Value) Value

Exp implements `**` for numbers.

func Member

func Member(v Value, name string) (Value, bool)

Member returns the named FEEL property of a temporal or duration value and reports whether v has such a property. It backs path access for these types; non-temporal values return ok=false so the caller can fall back to context member lookup.

func Mul

func Mul(a, b Value) Value

Mul implements `*`: number*number and duration*number (either order).

func Neg

func Neg(a Value) Value

Neg implements unary `-` for numbers and durations.

func ParseDuration

func ParseDuration(s string) (Value, error)

ParseDuration parses an ISO 8601 duration into either a years-months or a days-time duration. The two FEEL duration types are disjoint, so a literal mixing year/month and day/time components is rejected. Fractional components (e.g. PT1.5H) are not yet accepted — a documented limitation tracked for a later refinement.

func Sub

func Sub(a, b Value) Value

Sub implements `-`: numbers, like-typed durations, temporal differences and date/time minus duration.

type YearsMonthsDuration

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

YearsMonthsDuration is a duration measured in whole months (may be negative).

func NewYearsMonthsDuration

func NewYearsMonthsDuration(months int64) YearsMonthsDuration

NewYearsMonthsDuration builds a years-and-months duration from a month count.

func YearsMonthsBetween

func YearsMonthsBetween(from, to Date) YearsMonthsDuration

YearsMonthsBetween returns the difference from→to as a whole-month duration, truncated toward zero (e.g. 2020-01-01 → 2021-06-15 is P1Y5M).

func (YearsMonthsDuration) Kind

func (YearsMonthsDuration) Kind() Kind

Kind returns KindYearsMonthsDuration.

func (YearsMonthsDuration) Months

func (d YearsMonthsDuration) Months() int64

Months returns the total number of months (may be negative).

func (YearsMonthsDuration) String

func (d YearsMonthsDuration) String() string

Jump to

Keyboard shortcuts

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