1
0
mirror of https://github.com/danog/liquid.git synced 2024-12-02 22:07:48 +01:00
liquid/expression/functional.go
2017-07-04 11:12:40 -04:00

32 lines
706 B
Go

package expression
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
},
}
}