celiter

package module
v0.0.0-...-d4ad9c4 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2024 License: MIT Imports: 6 Imported by: 0

README

celiter

Build iterable values to use in CEL expressions. Compatible with the Go standard library's iter package.

Installation

$ go get github.com/picatz/celiter@latest

Documentation

Index

Constants

This section is empty.

Variables

Type is the type of the iterable value. Use this when defining custom CEL functions that handle (or return) iterable values.

These values are iterable, indexable, and have a size.

Functions

func AsSeq

func AsSeq[T any](val ref.Val, convert func(ref.Val) T) iter.Seq[T]

AsSeq converts a CEL iterable Value instance to a sequence of elements.

Important

  1. If the iterable is not a CEL iterable, an empty sequence is returned.
  2. If there are any errors during conversion, the sequence will be truncated, or the program could panic.
  3. Probably not a good idea to use this function in production code, but really useful for testing, debugging, and REPL-like environments where you want to quickly convert between CEL and Go types.

Types

type Convert

type Convert[T any] func(T) ref.Val

Convert is a function that converts an element of type T to a ref.Val type which can be used in CEL expressions.

type HasNext

type HasNext func() (bool, error)

HasNext is a function that checks if there is a next element in the iterable.

type Next

type Next[T any] func() (T, error)

Next is a function that retrieves the next element in the iterable.

type Value

type Value[T any] struct {
	// contains filtered or unexported fields
}

Value represents an iterable value in CEL expressions.

func FromSeq

func FromSeq[T any](seq iter.Seq[T], convert Convert[T]) *Value[T]

FromSeq creates a new iterable Value instance from a sequence of elements, which allows for simple interoperability between Go and CEL iterable types.

func New

func New[T any](hasNext HasNext, next Next[T], convert Convert[T]) *Value[T]

New created a new iterable Value instance for use in CEL expressions.

func (*Value[T]) Contains

func (v *Value[T]) Contains(val ref.Val) ref.Val

Contains checks if the iterable value contains the given value.

func (*Value[T]) ConvertToNative

func (v *Value[T]) ConvertToNative(typ reflect.Type) (any, error)

ConvertToNative converts the current iterable value to a native Go type.

func (*Value[T]) ConvertToType

func (ci *Value[T]) ConvertToType(typ ref.Type) ref.Val

ConvertToType converts the current iterable value to a ref.Val type.

func (*Value[T]) Equal

func (ci *Value[T]) Equal(other ref.Val) ref.Val

Equal checks if the current iterable value is equal to another ref.Val type.

func (*Value[T]) Get

func (v *Value[T]) Get(key ref.Val) ref.Val

Get retrieves the value at the given key index, allowing for random access of the iterable value using an index value (like an array).

func (*Value[T]) HasNext

func (ci *Value[T]) HasNext() ref.Val

HasNext checks if there is a next element in the iterable value.

func (*Value[T]) Iterator

func (ci *Value[T]) Iterator() traits.Iterator

Iterator returns the current iterable value, satisfying the traits.Iterator interface.

func (*Value[T]) Next

func (ci *Value[T]) Next() ref.Val

Next retrieves the next element in the iterable value.

func (*Value[T]) Size

func (v *Value[T]) Size() ref.Val

Size returns the size of the iterable value.

func (*Value[T]) Type

func (ci *Value[T]) Type() ref.Type

Type returns the type of the iterable value.

func (*Value[T]) Value

func (ci *Value[T]) Value() any

Value returns the current value of the iterable.

Jump to

Keyboard shortcuts

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