Skip to content

Commit 9aa0151

Browse files
committed
Some example
1 parent 39e433d commit 9aa0151

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed

example/build.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
psc-package build
2+
purs-tsd-gen -d output
3+
tsc --strict user.ts

example/psc-package.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "example",
3+
"set": "psc-0.13.0",
4+
"source": "https://github.com/purescript/package-sets.git",
5+
"depends": [
6+
"console",
7+
"effect",
8+
"foreign-object",
9+
"nullable",
10+
"prelude",
11+
"variant"
12+
]
13+
}

example/src/Main.purs

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
module Main where
2+
3+
import Prelude (Unit, show, (#), ($), (+))
4+
import Effect (Effect)
5+
import Effect.Console (log)
6+
import Data.Variant (SProxy(..), Variant, case_, on)
7+
import Data.Nullable (Nullable, toMaybe)
8+
import Data.Maybe (Maybe(..))
9+
import Data.Tuple (Tuple(..))
10+
import Foreign.Object (Object, fromFoldable)
11+
import Effect.Uncurried (EffectFn2, mkEffectFn2)
12+
13+
main :: Effect Unit
14+
main = do
15+
log "Hello sailor!"
16+
17+
variantToString :: Variant (num :: Number, str :: String) -> String
18+
variantToString = case_ # on (SProxy :: SProxy "num") show
19+
# on (SProxy :: SProxy "str") (\x -> x)
20+
21+
nullableToString :: Nullable String -> String
22+
nullableToString x = case toMaybe x of
23+
Just y -> y
24+
Nothing -> "null"
25+
26+
numToSomeObj :: Number -> Object Number
27+
numToSomeObj x = fromFoldable [Tuple "foo" x, Tuple "bar" (x + 1.0)]
28+
29+
someEffectFn :: EffectFn2 Number Number Unit
30+
someEffectFn = mkEffectFn2 $ \a b -> do
31+
log (show (a + b))
32+
33+
-- Function s t
34+
-- Array t
35+
-- Record { key1 :: Type1, key2 :: Type2 }
36+
-- Number, Int
37+
-- String, Char
38+
-- Boolean
39+
-- Tuple a b
40+
-- Maybe a
41+
-- Either a b
42+
-- Data.Function.Uncurried
43+
-- Effect
44+
-- Control.Monad.Eff
45+
-- Data.StrMap.StrMap
46+
-- Data.Variant
47+
-- Data.Nullable

example/user.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import * as PursExample from "./output/Main";
2+
3+
console.log(PursExample.variantToString({type: "num", value: 123})); // => "123"
4+
console.log(PursExample.nullableToString(null)); // => "null"
5+
console.log(PursExample.numToSomeObj(42).bar); // => 43
6+
PursExample.someEffectFn(23, 42); // => 65.0

0 commit comments

Comments
 (0)