-
Notifications
You must be signed in to change notification settings - Fork 0
/
value.gleam
53 lines (44 loc) · 826 Bytes
/
value.gleam
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
import kreator/utils/string.{parenthesify} as _
import gleam/string_builder.{type StringBuilder}
import gleam/list
pub type Value {
String(String)
Int(Int)
Float(Float)
Bool(Bool)
Raw(String)
Null
List(List(Value))
}
pub fn to_placeholder(value: Value) -> StringBuilder {
case value {
Raw(v) -> string_builder.from_string(v)
List(v) ->
v
|> list.map(to_placeholder)
|> string_builder.join(", ")
|> parenthesify
_ -> string_builder.from_string("?")
}
}
pub fn int(i: Int) -> Value {
Int(i)
}
pub fn string(i: String) -> Value {
String(i)
}
pub fn bool(i: Bool) -> Value {
Bool(i)
}
pub fn float(i: Float) -> Value {
Float(i)
}
pub fn list(i: List(Value)) -> Value {
List(i)
}
pub fn raw(i: String) -> Value {
Raw(i)
}
pub fn null() -> Value {
Null
}