git.iko.soy/rowtype-yoga/purescript-native
on bd188c8 help sign in
54 lines 856 B history raw
1package purescript
3//go:generate purs --version
5import "sync"
7type Any interface{}
9type Fn = func(Any) Any
10type EffFn = func() Any
12type Once = sync.Once
14type IGNORE_UNUSED_RUNTIME = bool
16const Undefined = "undefined"
18func Apply(f Any, args ...Any) Any {
19 result := f
20 for _, arg := range args {
21 fn, _ := result.(Fn)
22 result = fn(arg)
23 }
24 return result
27func Run(f Any, args ...Any) Any {
28 fn, _ := f.(EffFn)
29 return fn()
32func Get(dict Any, key string) Any {
33 d, _ := dict.(map[string]Any)
34 return d[key]
37func SafeGet(dict map[string]Any, key string) Any {
38 value, ok := dict[key]
39 if !ok {
40 panic("Foreign value '" + key + "' not defined")
41 }
42 return value
45func Contains(dict Any, key string) bool {
46 d, _ := dict.(map[string]Any)
47 _, found := d[key]
48 return found
51func Length(arr Any) Any {
52 a, _ := arr.([]Any)
53 return len(a)