module Update.UpdateEdition ( updateEdition , EditionAction(..) ) where import Char import Char exposing (KeyCode) import Model.Edition.Edition exposing (..) import Utils.List exposing (..) type EditionAction = DeleteLast | AddChar KeyCode updateEdition : EditionAction -> Edition -> Edition updateEdition action edition = case action of DeleteLast -> case maybeTail edition.chars of Just tailChars -> { edition | chars <- tailChars } Nothing -> edition AddChar keyCode -> case keyCodeToChar edition.kind keyCode of Just char -> if keyCode == 32 && maybeHead edition.chars == Just (Char.fromCode 32) then edition else { edition | chars <- char :: edition.chars } Nothing -> edition