mirror of
https://github.com/MontFerret/ferret.git
synced 2024-12-14 11:23:02 +02:00
1af8b37a0f
* New type system * Fixed dot notation for HTML elements
37 lines
722 B
Go
37 lines
722 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.Collection)
|
|
|
|
if !ok {
|
|
return values.None, core.TypeError(value.Type(),
|
|
types.String,
|
|
types.Array,
|
|
types.Object,
|
|
types.HTMLElement,
|
|
types.HTMLDocument,
|
|
types.Binary,
|
|
core.NewType("Collection"),
|
|
)
|
|
}
|
|
|
|
return c.Length(), nil
|
|
}
|