1
0
mirror of https://github.com/danog/liquid.git synced 2024-11-27 00:34:41 +01:00
liquid/expressions/functional.go
2017-07-13 20:18:23 -04:00

32 lines
707 B
Go

package expressions
type expressionWrapper struct {
fn func(ctx Context) (interface{}, error)
}
func (w expressionWrapper) Evaluate(ctx Context) (interface{}, error) {
return w.fn(ctx)
}
// Constant creates an expression that returns a constant value.
func Constant(k interface{}) Expression {
return expressionWrapper{
func(_ Context) (interface{}, error) {
return k, nil
},
}
}
// Not creates an expression that returns ! of the wrapped expression.
func Not(e Expression) Expression {
return expressionWrapper{
func(ctx Context) (interface{}, error) {
value, err := e.Evaluate(ctx)
if err != nil {
return nil, err
}
return (value == nil || value == false), nil
},
}
}