You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 16, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: pkg/builtin/functions.go
+51-51Lines changed: 51 additions & 51 deletions
Original file line number
Diff line number
Diff line change
@@ -16,39 +16,39 @@ var (
16
16
humaneCoalescer=coalescing.NewHumane()
17
17
18
18
CoreFunctions= types.Functions{
19
-
"default": native.NewFunction("returns the default value if the first argument is empty", defaultFunction),
19
+
"default": native.NewFunction(defaultFunction).WithDescription("returns the default value if the first argument is empty"),
20
20
"delete": deleteFunction{},
21
-
"do": native.NewFunction("eval a sequence of statements where only one expression is valid", doFunction),
22
-
"empty?": native.NewFunction("returns true when the given value is empty-ish (0, false, null, \"\", ...)", isEmptyFunction).WithCoalescer(humaneCoalescer),
23
-
"error": native.NewFunction("returns an error", errorFunction),
24
-
"has?": native.NewFunction("returns true if the given symbol's path expression points to an existing value", hasFunction),
25
-
"if": native.NewFunction("evaluate one of two expressions based on a condition", ifElseFunction, ifFunction),
26
-
"set": native.NewFunction("set a value in a variable/document, only really useful with ! modifier (set!)", setFunction),
27
-
"try": native.NewFunction("returns the fallback if the first expression errors out", tryWithFallbackFunction, tryFunction),
21
+
"do": native.NewFunction(doFunction).WithDescription("eval a sequence of statements where only one expression is valid"),
22
+
"empty?": native.NewFunction(isEmptyFunction).WithCoalescer(humaneCoalescer).WithDescription("returns true when the given value is empty-ish (0, false, null, \"\", ...)"),
23
+
"error": native.NewFunction(errorFunction).WithDescription("returns an error"),
24
+
"has?": native.NewFunction(hasFunction).WithDescription("returns true if the given symbol's path expression points to an existing value"),
25
+
"if": native.NewFunction(ifElseFunction, ifFunction).WithDescription("evaluate one of two expressions based on a condition"),
26
+
"set": native.NewFunction(setFunction).WithDescription("set a value in a variable/document, only really useful with ! modifier (set!)"),
27
+
"try": native.NewFunction(tryWithFallbackFunction, tryFunction).WithDescription("returns the fallback if the first expression errors out"),
28
28
}
29
29
30
30
LogicFunctions= types.Functions{
31
-
"and": native.NewFunction("returns true if all arguments are true", andFunction),
32
-
"or": native.NewFunction("returns true if any of the arguments is true", orFunction),
33
-
"not": native.NewFunction("negates the given argument", notFunction),
31
+
"and": native.NewFunction(andFunction).WithDescription("returns true if all arguments are true"),
32
+
"or": native.NewFunction(orFunction).WithDescription("returns true if any of the arguments is true"),
33
+
"not": native.NewFunction(notFunction).WithDescription("negates the given argument"),
34
34
}
35
35
36
36
ComparisonFunctions= types.Functions{
37
-
"eq?": native.NewFunction("equality check: return true if both arguments are the same", eqFunction),
38
-
"identical?": native.NewFunction("like `eq?`, but always uses strict coalecsing", identicalFunction),
39
-
"like?": native.NewFunction("like `eq?`, but always uses humane coalecsing", likeFunction),
40
-
41
-
"lt?": native.NewFunction("returns a < b", ltCoalescer),
42
-
"lte?": native.NewFunction("returns a <= b", lteCoalescer),
43
-
"gt?": native.NewFunction("returns a > b", gtCoalescer),
44
-
"gte?": native.NewFunction("returns a >= b", gteCoalescer),
37
+
"eq?": native.NewFunction(eqFunction).WithDescription("equality check: return true if both arguments are the same"),
38
+
"identical?": native.NewFunction(identicalFunction).WithDescription("like `eq?`, but always uses strict coalecsing"),
39
+
"like?": native.NewFunction(likeFunction).WithDescription("like `eq?`, but always uses humane coalecsing"),
40
+
41
+
"lt?": native.NewFunction(ltCoalescer).WithDescription("returns a < b"),
42
+
"lte?": native.NewFunction(lteCoalescer).WithDescription("returns a <= b"),
43
+
"gt?": native.NewFunction(gtCoalescer).WithDescription("returns a > b"),
44
+
"gte?": native.NewFunction(gteCoalescer).WithDescription("returns a >= b"),
45
45
}
46
46
47
47
// aliases to make bang functions nicer (add! vs +!)
48
-
addRudiFunction=native.NewFunction("returns the sum of all of its arguments", numberAddFunction, integerAddFunction)
lenRudiFunction=native.NewFunction("returns the length of a string, vector or object", stringLenFunction, vectorLenFunction, objectLenFunction)
67
-
appendRudiFunction=native.NewFunction("appends more strings to a string or arbitrary items into a vector", appendToVectorFunction, appendToStringFunction)
68
-
prependRudiFunction=native.NewFunction("prepends more strings to a string or arbitrary items into a vector", prependToVectorFunction, prependToStringFunction)
69
-
reverseRudiFunction=native.NewFunction("reverses a string or the elements of a vector", reverseVectorFunction, reverseStringFunction)
70
-
containsRudiFunction=native.NewFunction("returns true if a string contains a substring or a vector contains the given element", stringContainsFunction, vectorContainsFunction)
66
+
lenRudiFunction=native.NewFunction(stringLenFunction, vectorLenFunction, objectLenFunction).WithDescription("returns the length of a string, vector or object")
67
+
appendRudiFunction=native.NewFunction(appendToVectorFunction, appendToStringFunction).WithDescription("appends more strings to a string or arbitrary items into a vector")
68
+
prependRudiFunction=native.NewFunction(prependToVectorFunction, prependToStringFunction).WithDescription("prepends more strings to a string or arbitrary items into a vector")
69
+
reverseRudiFunction=native.NewFunction(reverseVectorFunction, reverseStringFunction).WithDescription("reverses a string or the elements of a vector")
70
+
containsRudiFunction=native.NewFunction(stringContainsFunction, vectorContainsFunction).WithDescription("returns true if a string contains a substring or a vector contains the given element")
71
71
72
72
StringsFunctions= types.Functions{
73
73
// these ones are shared with ListsFunctions
@@ -77,15 +77,15 @@ var (
77
77
"reverse": reverseRudiFunction,
78
78
"contains?": containsRudiFunction,
79
79
80
-
"concat": native.NewFunction("concatenates items in a vector using a common glue string", concatFunction),
81
-
"split": native.NewFunction("splits a string into a vector", splitFunction),
82
-
"has-prefix?": native.NewFunction("returns true if the given string has the prefix", hasPrefixFunction),
83
-
"has-suffix?": native.NewFunction("returns true if the given string has the suffix", hasSuffixFunction),
84
-
"trim-prefix": native.NewFunction("removes the prefix from the string, if it exists", trimPrefixFunction),
85
-
"trim-suffix": native.NewFunction("removes the suffix from the string, if it exists", trimSuffixFunction),
86
-
"to-lower": native.NewFunction("returns the lowercased version of the given string", toLowerFunction),
87
-
"to-upper": native.NewFunction("returns the uppercased version of the given string", toUpperFunction),
88
-
"trim": native.NewFunction("returns the given whitespace with leading/trailing whitespace removed", trimFunction),
80
+
"concat": native.NewFunction(concatFunction).WithDescription("concatenates items in a vector using a common glue string"),
81
+
"split": native.NewFunction(splitFunction).WithDescription("splits a string into a vector"),
82
+
"has-prefix?": native.NewFunction(hasPrefixFunction).WithDescription("returns true if the given string has the prefix"),
83
+
"has-suffix?": native.NewFunction(hasSuffixFunction).WithDescription("returns true if the given string has the suffix"),
84
+
"trim-prefix": native.NewFunction(trimPrefixFunction).WithDescription("removes the prefix from the string, if it exists"),
85
+
"trim-suffix": native.NewFunction(trimSuffixFunction).WithDescription("removes the suffix from the string, if it exists"),
86
+
"to-lower": native.NewFunction(toLowerFunction).WithDescription("returns the lowercased version of the given string"),
87
+
"to-upper": native.NewFunction(toUpperFunction).WithDescription("returns the uppercased version of the given string"),
88
+
"trim": native.NewFunction(trimFunction).WithDescription("returns the given whitespace with leading/trailing whitespace removed"),
89
89
}
90
90
91
91
ListsFunctions= types.Functions{
@@ -102,34 +102,34 @@ var (
102
102
}
103
103
104
104
HashingFunctions= types.Functions{
105
-
"sha1": native.NewFunction("return the lowercase hex representation of the SHA-1 hash", sha1Function),
106
-
"sha256": native.NewFunction("return the lowercase hex representation of the SHA-256 hash", sha256Function),
107
-
"sha512": native.NewFunction("return the lowercase hex representation of the SHA-512 hash", sha512Function),
105
+
"sha1": native.NewFunction(sha1Function).WithDescription("return the lowercase hex representation of the SHA-1 hash"),
106
+
"sha256": native.NewFunction(sha256Function).WithDescription("return the lowercase hex representation of the SHA-256 hash"),
107
+
"sha512": native.NewFunction(sha512Function).WithDescription("return the lowercase hex representation of the SHA-512 hash"),
108
108
}
109
109
110
110
EncodingFunctions= types.Functions{
111
-
"to-base64": native.NewFunction("apply base64 encoding to the given string", toBase64Function),
112
-
"from-base64": native.NewFunction("decode a base64 encoded string", fromBase64Function),
111
+
"to-base64": native.NewFunction(toBase64Function).WithDescription("apply base64 encoding to the given string"),
112
+
"from-base64": native.NewFunction(fromBase64Function).WithDescription("decode a base64 encoded string"),
113
113
}
114
114
115
115
DateTimeFunctions= types.Functions{
116
-
"now": native.NewFunction("returns the current date & time (UTC), formatted like a Go date", nowFunction),
116
+
"now": native.NewFunction(nowFunction).WithDescription("returns the current date & time (UTC), formatted like a Go date"),
117
117
}
118
118
119
119
TypeFunctions= types.Functions{
120
-
"type-of": native.NewFunction(`returns the type of a given value (e.g. "string" or "number")`, typeOfFunction),
120
+
"type-of": native.NewFunction(typeOfFunction).WithDescription(`returns the type of a given value (e.g. "string" or "number")`),
121
121
122
122
// these functions purposefully always uses humane coalescing
123
-
"to-bool": native.NewFunction("try to convert the given argument losslessly to a bool", toBoolFunction).WithCoalescer(humaneCoalescer),
124
-
"to-float": native.NewFunction("try to convert the given argument losslessly to a float64", toFloatFunction).WithCoalescer(humaneCoalescer),
125
-
"to-int": native.NewFunction("try to convert the given argument losslessly to an int64", toIntFunction).WithCoalescer(humaneCoalescer),
126
-
"to-string": native.NewFunction("try to convert the given argument losslessly to a string", toStringFunction).WithCoalescer(humaneCoalescer),
123
+
"to-bool": native.NewFunction(toBoolFunction).WithCoalescer(humaneCoalescer).WithDescription("try to convert the given argument losslessly to a bool"),
124
+
"to-float": native.NewFunction(toFloatFunction).WithCoalescer(humaneCoalescer).WithDescription("try to convert the given argument losslessly to a float64"),
125
+
"to-int": native.NewFunction(toIntFunction).WithCoalescer(humaneCoalescer).WithDescription("try to convert the given argument losslessly to an int64"),
126
+
"to-string": native.NewFunction(toStringFunction).WithCoalescer(humaneCoalescer).WithDescription("try to convert the given argument losslessly to a string"),
127
127
}
128
128
129
129
CoalescingContextFunctions= types.Functions{
130
-
"strictly": native.NewFunction("evaluates the child expressions using strict coalescing", doFunction).WithCoalescer(strictCoalescer),
131
-
"pedantically": native.NewFunction("evaluates the child expressions using pedantic coalescing", doFunction).WithCoalescer(pedanticCoalescer),
132
-
"humanely": native.NewFunction("evaluates the child expressions using humane coalescing", doFunction).WithCoalescer(humaneCoalescer),
130
+
"strictly": native.NewFunction(doFunction).WithCoalescer(strictCoalescer).WithDescription("evaluates the child expressions using strict coalescing"),
131
+
"pedantically": native.NewFunction(doFunction).WithCoalescer(pedanticCoalescer).WithDescription("evaluates the child expressions using pedantic coalescing"),
132
+
"humanely": native.NewFunction(doFunction).WithCoalescer(humaneCoalescer).WithDescription("evaluates the child expressions using humane coalescing"),
0 commit comments