@@ -0,0 +1,167 @@
1+module Realistic.Todo15 (benchmark) where
7+benchmark : Benchmark.Benchmark
9+ Benchmark.suite "todomvc business logic"
10+ [ run "type in 5 todos, each 15 characters long" typingActions
11+ , run "do everything" batchActions
15+run : String -> List Action -> Benchmark.Benchmark
16+run description actions =
18+ (description ++ " - " ++ toString (List.length actions) ++ " actions")
19+ (\_ -> List.foldl update emptyModel actions)
25+ List.map (\n -> UpdateField (String.repeat n "X")) [1..15]
28+ List.concatMap enter [1..5]
34+ [ UpdateField ("My task " ++ toString i)
40+ , UpdateTask i "New Task text"
41+ , EditingTask i False
54+ [ List.concatMap addTask [1..50]
55+ , [CheckAll True, CheckAll False]
56+ , List.concatMap editTask (List.filter isEven [1 .. 50])
57+ , List.map check [5, 7, 9, 13, 17, 23, 37]
58+ , List.map uncheck [7, 13, 23, 37]
59+ , [DeleteComplete, Delete 7, Delete 23]
60+ , List.concatMap addTask [51..80]
61+ , List.map check (List.filter isEven [51..80])
62+ , [DeleteComplete, CheckAll True, DeleteComplete]
74+ , visibility : String
79+ { description : String
86+newTask : String -> Int -> Task
110+ | UpdateField String
111+ | EditingTask Int Bool
112+ | UpdateTask Int String
118+ | ChangeVisibility String
121+update : Action -> Model -> Model
122+update action model =
128+ uid <- model.uid + 1,
131+ if String.isEmpty model.field
133+ else model.tasks ++ [newTask model.field model.uid]
137+ { model | field <- str }
139+ EditingTask id isEditing ->
140+ let updateTask t = if t.id == id then { t | editing <- isEditing } else t
142+ { model | tasks <- List.map updateTask model.tasks }
144+ UpdateTask id task ->
145+ let updateTask t = if t.id == id then { t | description <- task } else t
147+ { model | tasks <- List.map updateTask model.tasks }
150+ { model | tasks <- List.filter (\t -> t.id /= id) model.tasks }
153+ { model | tasks <- List.filter (not << .completed) model.tasks }
155+ Check id isCompleted ->
156+ let updateTask t = if t.id == id then { t | completed <- isCompleted } else t
158+ { model | tasks <- List.map updateTask model.tasks }
160+ CheckAll isCompleted ->
161+ let updateTask t = { t | completed <- isCompleted }
163+ { model | tasks <- List.map updateTask model.tasks }
165+ ChangeVisibility visibility ->
166+ { model | visibility <- visibility }