forked from andyarvanitis/purescript-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
232 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package purescript_effect | ||
|
||
import ( | ||
. "github.com/purescript-native/go-runtime" | ||
) | ||
|
||
func init() { | ||
exports := Foreign("Effect.Uncurried") | ||
|
||
exports["runEffectFn1"] = func(fn Any) Any { | ||
return func(a Any) Any { | ||
return func() Any { | ||
return Apply(fn, a) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package purescript_effect | ||
|
||
import ( | ||
. "github.com/purescript-native/go-runtime" | ||
) | ||
|
||
func init() { | ||
exports := Foreign("Effect.Unsafe") | ||
|
||
exports["unsafePerformEffect"] = func(f Any) Any { | ||
return Run(f) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package purescript_foreign | ||
|
||
import ( | ||
. "github.com/purescript-native/go-runtime" | ||
) | ||
|
||
func init() { | ||
exports := Foreign("Foreign") | ||
|
||
exports["unsafeToForeign"] = func(value Any) Any { | ||
return value | ||
} | ||
|
||
exports["unsafeFromForeign"] = func(value Any) Any { | ||
return value | ||
} | ||
|
||
exports["typeOf"] = func(value Any) Any { | ||
switch value.(type) { | ||
case string: | ||
return "string" | ||
|
||
case float64: | ||
return "number" | ||
|
||
case int: | ||
return "number" | ||
|
||
case bool: | ||
return "boolean" | ||
|
||
case Dict: | ||
return "object" | ||
|
||
case Any: | ||
return "object" | ||
|
||
case nil: | ||
return "object" | ||
|
||
default: | ||
return "undefined" | ||
} | ||
} | ||
|
||
exports["tagOf"] = func(value Any) Any { | ||
switch value.(type) { | ||
case string: | ||
return "String" | ||
|
||
case float64: | ||
return "Number" | ||
|
||
case int: | ||
return "Number" | ||
|
||
case bool: | ||
return "Boolean" | ||
|
||
case Dict: | ||
return "Object" | ||
|
||
case Any: | ||
return "Array" | ||
|
||
case nil: | ||
return "Null" | ||
|
||
default: | ||
return "Undefined" | ||
} | ||
} | ||
|
||
exports["isNull"] = func(value Any) Any { | ||
return value == nil | ||
} | ||
|
||
exports["isUndefined"] = func(value Any) Any { | ||
return false | ||
} | ||
|
||
exports["isArray"] = func(value Any) Any { | ||
_, ok := value.([]Any) | ||
return ok | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package purescript_foreign | ||
|
||
import ( | ||
. "github.com/purescript-native/go-runtime" | ||
) | ||
|
||
func init() { | ||
exports := Foreign("Foreign.Index") | ||
|
||
exports["unsafeReadPropImpl"] = func(f, s, key_, value_ Any) Any { | ||
value, ok := value_.(Dict) | ||
if !ok { | ||
return f | ||
} | ||
key, _ := key_.(string) | ||
return Apply(s, value[key]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package purescript_global | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
. "github.com/purescript-native/go-runtime" | ||
) | ||
|
||
func init() { | ||
exports := Foreign("Global.Unsafe") | ||
|
||
exports["unsafeStringify"] = func(value Any) Any { | ||
blob, err := json.Marshal(value) | ||
if err != nil { | ||
panic(err.Error()) | ||
} | ||
return string(blob) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package purescript_nullable | ||
|
||
import ( | ||
. "github.com/purescript-native/go-runtime" | ||
) | ||
|
||
func init() { | ||
exports := Foreign("Data.Nullable") | ||
|
||
exports["null"] = nil | ||
|
||
exports["nullable"] = func(a, r, f Any) Any { | ||
if a == nil { | ||
return r | ||
} | ||
return Apply(f, a) | ||
} | ||
|
||
exports["notNull"] = func(x Any) Any { | ||
return x | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package purescript_record | ||
|
||
import ( | ||
. "github.com/purescript-native/go-runtime" | ||
) | ||
|
||
func init() { | ||
exports := Foreign("Record.Builder") | ||
|
||
exports["copyRecord"] = func(rec_ Any) Any { | ||
rec, _ := rec_.(Dict) | ||
cpy := make(Dict) | ||
for key, value := range rec { | ||
cpy[key] = value | ||
} | ||
return cpy | ||
} | ||
|
||
exports["unsafeInsert"] = func(l_ Any) Any { | ||
return func(a Any) Any { | ||
return func(rec_ Any) Any { | ||
l, _ := l_.(string) | ||
rec, _ := rec_.(Dict) | ||
rec[l] = a | ||
return rec | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package purescript_global | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
. "github.com/purescript-native/go-runtime" | ||
) | ||
|
||
func init() { | ||
exports := Foreign("Simple.JSON") | ||
|
||
exports["_parseJSON"] = func(text_ Any) Any { | ||
text, _ := text_.(string) | ||
var result Any | ||
if err := json.Unmarshal([]byte(text), &result); err != nil { | ||
panic(err.Error()) | ||
} | ||
return result | ||
} | ||
|
||
exports["_undefined"] = nil | ||
} |