Skip to content
This repository was archived by the owner on Mar 16, 2025. It is now read-only.

Commit 12194f9

Browse files
committed
reimplement map/range/filter
1 parent e783c86 commit 12194f9

2 files changed

Lines changed: 214 additions & 301 deletions

File tree

pkg/builtin/functions.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package builtin
66
import (
77
"go.xrstf.de/rudi/pkg/coalescing"
88
"go.xrstf.de/rudi/pkg/eval/types"
9-
"go.xrstf.de/rudi/pkg/eval/util"
109
"go.xrstf.de/rudi/pkg/eval/util/native"
1110
)
1211

@@ -96,9 +95,24 @@ var (
9695
"reverse": reverseRudiFunction,
9796
"contains?": containsRudiFunction,
9897

99-
"range": util.NewRawFunction(rangeFunction, "allows to iterate (loop) over a vector or object").MinArgs(3),
100-
"map": util.NewRawFunction(mapFunction, "applies an expression to every element in a vector or object").MinArgs(2),
101-
"filter": util.NewRawFunction(filterFunction, "returns a copy of a given vector/object with only those elements remaining that satisfy a condition").MinArgs(2),
98+
"range": native.NewFunction(
99+
rangeVectorFunction,
100+
rangeObjectFunction,
101+
).WithDescription("allows to iterate (loop) over a vector or object"),
102+
103+
"map": native.NewFunction(
104+
mapVectorExpressionFunction,
105+
mapObjectExpressionFunction,
106+
mapVectorAnonymousFunction,
107+
mapObjectAnonymousFunction,
108+
).WithDescription("applies an expression to every element in a vector or object"),
109+
110+
"filter": native.NewFunction(
111+
filterVectorExpressionFunction,
112+
filterObjectExpressionFunction,
113+
filterVectorAnonymousFunction,
114+
filterObjectAnonymousFunction,
115+
).WithDescription("returns a copy of a given vector/object with only those elements remaining that satisfy a condition"),
102116
}
103117

104118
HashingFunctions = types.Functions{

0 commit comments

Comments
 (0)