-
Notifications
You must be signed in to change notification settings - Fork 1
/
subscription.gleam
61 lines (51 loc) · 1.06 KB
/
subscription.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
54
55
56
57
58
59
60
61
import gleam/int
import gleam/result
import glitch/event_sub/subscription/user.{
type InvalidUserSubscription, type User,
}
pub type Subscription {
Subscription(name: Name, version: Version, condition: Condition)
}
pub type Name {
User(User)
}
pub type InvalidName {
InvalidUser(InvalidUserSubscription)
}
pub fn name_to_string(name: Name) -> String {
case name {
User(user) -> user.to_string(user)
}
}
pub fn name_from_string(str: String) -> Result(Name, InvalidName) {
str
|> user.from_string
|> result.map(User)
|> result.map_error(InvalidUser)
}
pub type Condition {
Condition
}
pub type Version {
Int(Int)
Beta
}
pub type InvalidVersion {
InvalidVersion(String)
}
pub fn version_to_string(version: Version) -> String {
case version {
Int(version) -> int.to_string(version)
Beta -> "beta"
}
}
pub fn version_from_string(str: String) -> Result(Version, InvalidVersion) {
case str {
"beta" -> Ok(Beta)
_ ->
str
|> int.parse
|> result.map(Int)
|> result.replace_error(InvalidVersion(str))
}
}