cleaner event handler for FixCodeEvent

This commit is contained in:
Jonathan Lamothe 2024-08-15 16:52:23 -04:00
parent 1e37c2c47b
commit 44588c691a

View File

@ -24,7 +24,7 @@ License along with this program. If not, see
|-}
{-# LANGUAGE LambdaCase, OverloadedStrings #-}
{-# LANGUAGE OverloadedStrings #-}
module Hamming.App.Events (
eventHandler,
@ -47,7 +47,7 @@ import Brick.Keybindings
, onEvent
)
import Control.Monad (void)
import Control.Monad.State.Class (get, gets, modify, put)
import Control.Monad.State.Class (gets, modify, put)
import Data.Either (fromRight)
import Graphics.Vty.Input.Events
( Event (EvKey)
@ -95,10 +95,7 @@ keyEventHandlers =
, onEvent CheckBitsEvent "Set Check Bits" $
hammingCode %= setCheckBits
, onEvent FixCodeEvent "Attempt to Correct Errors" $
zoom hammingCode $ get >>= \case
Nothing -> return ()
Just c -> put c
. correctErrors
zoom hammingCode $ gets correctErrors >>= mapM_ put
, onEvent ResetEvent "Reset Code" $
hammingCode .= 0
]