-
Notifications
You must be signed in to change notification settings - Fork 20
/
function.go
48 lines (38 loc) · 1.15 KB
/
function.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package types
import (
"github.com/nyaruka/goflow/envs"
"github.com/nyaruka/goflow/utils/jsonx"
)
// XFunction is a callable function.
//
// @(upper) -> function
// @(array(upper)[0]("abc")) -> ABC
// @(json(upper)) -> null
//
// @type function
type XFunction func(env envs.Environment, args ...XValue) XValue
// Describe returns a representation of this type for error messages
func (x XFunction) Describe() string { return "function" }
// Truthy determines truthiness for this type
func (x XFunction) Truthy() bool { return true }
// Render returns the canonical text representation
func (x XFunction) Render() string {
return "function"
}
// Format returns the pretty text representation
func (x XFunction) Format(env envs.Environment) string {
return x.Render()
}
// MarshalJSON converts this type to JSON
func (x XFunction) MarshalJSON() ([]byte, error) {
return jsonx.Marshal(nil)
}
// String returns the native string representation of this type
func (x XFunction) String() string {
return `XFunction`
}
// Equals determines equality for this type
func (x XFunction) Equals(other XFunction) bool {
return true // TODO
}
var _ XValue = XFunction(nil)