-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask_list.hum
More file actions
84 lines (65 loc) · 1.16 KB
/
Copy pathtask_list.hum
File metadata and controls
84 lines (65 loc) · 1.16 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
module examples.task_list
type Task {
title: Text
done: Bool
}
store tasks: list Task {
why:
remember the user's tasks
}
task add_item(title: Text) -> Result Task, TaskError {
why:
let the user remember something to do
changes:
tasks
needs:
title is not empty
ensures:
new item is saved
new item is not done
fails when:
title is empty
watch for:
title may be only spaces
cost:
time: O(1)
space: O(1)
allocates: one task
check: warn
avoids:
saving empty titles
does:
if title is empty {
fail TaskError.empty_title
}
let item = Task {
title: title
done: false
}
save item in tasks
return item
}
task show_tasks() {
why:
let the user see what they need to do
uses:
tasks
screen
needs:
task_store readable
cost:
time: O(tasks)
space: O(1)
allocates: nothing
check: warn
tradeoffs:
linear display is expected because every visible item must be shown
does:
for each item in tasks {
if item.done {
show item.title as completed
} else {
show item.title as active
}
}
}