1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-03-21 21:47:43 +02:00

38 lines
826 B
Go
Raw Normal View History

2018-09-18 16:42:38 -04:00
package collections
import (
"context"
2018-09-18 16:42:38 -04:00
"github.com/MontFerret/ferret/pkg/runtime/collections"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
"github.com/MontFerret/ferret/pkg/runtime/values/types"
2018-09-18 16:42:38 -04:00
)
// LENGTH returns the length of a measurable value.
// @param {Measurable} value - The value to measure.
// @return {Int} - The length of the value.
2018-09-18 16:42:38 -04:00
func Length(_ context.Context, inputs ...core.Value) (core.Value, error) {
err := core.ValidateArgs(inputs, 1, 1)
2018-09-18 16:42:38 -04:00
if err != nil {
return values.None, err
}
value := inputs[0]
c, ok := value.(collections.Measurable)
if !ok {
return values.None, core.TypeError(value.Type(),
types.String,
types.Array,
types.Object,
types.Binary,
core.NewType("Measurable"),
)
2018-09-18 16:42:38 -04:00
}
return c.Length(), nil
2018-09-18 16:42:38 -04:00
}