diff options
author | Joris Guyonvarch | 2015-03-21 15:57:37 +0100 |
---|---|---|
committer | Joris Guyonvarch | 2015-03-21 15:57:37 +0100 |
commit | d57ea4eda1339ae55f1f1f6341d1af6b1a690330 (patch) | |
tree | 668fae3e2f10c6915eeb90309f789a63a900b04e /src/Update/UpdateTimerEdition.elm | |
parent | c73c712a56213b327b9d53262b81c80a3e23dcae (diff) |
Can remove numbers in timer edition
Diffstat (limited to 'src/Update/UpdateTimerEdition.elm')
-rw-r--r-- | src/Update/UpdateTimerEdition.elm | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/src/Update/UpdateTimerEdition.elm b/src/Update/UpdateTimerEdition.elm index cff39f7..e9493eb 100644 --- a/src/Update/UpdateTimerEdition.elm +++ b/src/Update/UpdateTimerEdition.elm @@ -1,19 +1,34 @@ module Update.UpdateTimerEdition ( updateTimerEdition + , TimerEditionAction(..) ) where import Char (..) import Model.TimerEdition (..) -updateTimerEdition : Maybe Char -> TimerEdition -> TimerEdition -updateTimerEdition maybeChar timerEdition = - case maybeChar of - Just char -> - if isDigit char - then - { timerEdition | numbers <- char :: timerEdition.numbers } - else +import Utils.List (..) + +type TimerEditionAction = + DeleteLast + | AddNumber KeyCode + +updateTimerEdition : TimerEditionAction -> TimerEdition -> TimerEdition +updateTimerEdition action timerEdition = + case action of + DeleteLast -> + case maybeTail timerEdition.numbers of + Just tailNumbers -> + { timerEdition | numbers <- tailNumbers } + Nothing -> + timerEdition + AddNumber keyCode -> + case keyCodeToNumberChar keyCode of + Just char -> + if isDigit char + then + { timerEdition | numbers <- char :: timerEdition.numbers } + else + timerEdition + Nothing -> timerEdition - Nothing -> - timerEdition |