diff options
Diffstat (limited to 'src/Model')
-rw-r--r-- | src/Model/TimerEdition.elm | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/Model/TimerEdition.elm b/src/Model/TimerEdition.elm index 5feea33..2ec98b7 100644 --- a/src/Model/TimerEdition.elm +++ b/src/Model/TimerEdition.elm @@ -2,7 +2,7 @@ module Model.TimerEdition ( TimerEdition , Numbers , newTimerEdition - , keyCodeToChar + , keyCodeToNumberChar , toTime , toMinutesAndSeconds ) where @@ -16,6 +16,7 @@ import Keyboard (KeyCode) import Model.Id (..) import Utils.List (..) +import Utils.Maybe (..) type alias TimerEdition = { id : Id @@ -29,10 +30,16 @@ newTimerEdition id = , numbers = [] } -keyCodeToChar : KeyCode -> Maybe Char -keyCodeToChar code = - let zero = 96 - nine = zero + 9 +keyCodeToNumberChar : KeyCode -> Maybe Char +keyCodeToNumberChar code = + List.map (flip keyCodeToCharFromZero code) zeroKeyCodes + |> List.foldl orElse Nothing + +zeroKeyCodes = [48, 96] + +keyCodeToCharFromZero : KeyCode -> KeyCode -> Maybe Char +keyCodeToCharFromZero zero code = + let nine = zero + 9 in if code >= zero && code <= nine then ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] |> Array.fromList |