1
0
mirror of https://github.com/MontFerret/ferret.git synced 2024-12-23 01:24:30 +02:00
ferret/pkg/stdlib/collections/length.go
Tim Voronov 34c8c02258
Refactoring/externalized html (#234)
* Externalized HTML drivers

* Fixed unit tests

* Updated logging

* Added support to set default driver

* Updated GetIn and SetIn helpers
2019-02-19 18:10:18 -05:00

35 lines
677 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"
)
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
}