mirror of
https://github.com/MontFerret/ferret.git
synced 2025-02-01 13:07:49 +02:00
24d8eedd4c
* Added release notes * #509 fixedOCOD typo * Updated values * Updated comments * Changed stdlib docs format * Changed format of array in docs * Use 'any' instead of 'value' in docs * New format for optional params * Updated docs for testing package * Added namespace information
38 lines
826 B
Go
38 lines
826 B
Go
package collections
|
|
|
|
import (
|
|
"context"
|
|
|
|
"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"
|
|
)
|
|
|
|
// LENGTH returns the length of a measurable value.
|
|
// @param {Measurable} value - The value to measure.
|
|
// @return {Int} - The length of the value.
|
|
func Length(_ context.Context, inputs ...core.Value) (core.Value, error) {
|
|
err := core.ValidateArgs(inputs, 1, 1)
|
|
|
|
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"),
|
|
)
|
|
}
|
|
|
|
return c.Length(), nil
|
|
}
|