github expr-lang/expr v1.11.0

latest releases: v1.16.9, v1.16.8, v1.16.7...
19 months ago

Expr – an expression language for Go.

This release introduces a new API for defining functions inside Expr - expr.Function.

From an Expr expression is already possible to call any Go methods and functions, but Expr has to use reflect package in doing such calls.
In previous releases, Expr added a special case for func (...any) any to avoid using reflect. But such functions lack type information. With newly added expr.Function option now it's possible to define a fast function with optional types! Read more in the docs.

atoi := expr.Function(
	"atoi",
	func(params ...any) (any, error) {
		return strconv.Atoi(params[0].(string))
	},
	new(func(string) int),
)

program, err := expr.Compile(`atoi("42")`, atoi)

Also in this release:

  • Added bool condition optimization.
  • Added support for comments // and /* ... */.
  • Added support for negative indexes list[-1].
  • Predicate brackets are now optional all(list, .values > 0).
  • Added int() and float() builtins.
  • Improved built-in functions performance.

Don't miss a new expr release

NewReleases is sending notifications on new releases.