-
Notifications
You must be signed in to change notification settings - Fork 0
/
scratch.pc
64 lines (49 loc) 路 1.33 KB
/
scratch.pc
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
data.price?.take_if(|a| a != "")
enum List<T> =
| empty
| link(v: T, rest: list<T>)
fn List.of[A](values: ...A): list[A] =
list[A]().add(values)
fn (List) each(cb: fn(v: T)) =
match self
empty -> return
link(a, rest) ->
cb(a)
rest.each(cb)
fn (List) append(values: ...V) =
`adds the specified elements to the start of the list
range(values) |v|
self.add(v)
fn (List) append(v: V) =
`adds the specified elements to the start of the list
self.last().rest = link(v, empty)
fn (List) prepend(v: V) =
`adds the specified elements to the start of the list
self.first() = link(v, self.first())
(1 + 2).mod(3).pow(2).sqrt()
math.sqrt(math.pow(math.mod(1 + 2, 3), 2))
if v == none
error.Error
else
c * 20
if v == None
error.Error
else
Some(c) := v
c * 20
match v
None -> return error.Error
Some(c) ->
return c * 20
`derive implements this func
`Derive is a compiler plugin/generator similar to dart
`which runs automatically. Its not a macro more like a decorator.
fn UserData.fromJsonStr(data: str): UserData | JsonParseError =
// JsonParseError(line: line, pos: post, object: "UserData")
pass
type FetchDataError = FetchError | IOError | JsonParseError
#effects(IO)
fn fetch_data(route: str): Result[UserData] =
res := fetch(route)?
data := res.body.read_all()?
parse_json(data)?