patched 2020-19 in haskell
This commit is contained in:
		
					parent
					
						
							
								ee4fa81423
							
						
					
				
			
			
				commit
				
					
						dc4363d9e7
					
				
			
		
					 1 changed files with 3 additions and 3 deletions
				
			
		| 
						 | 
					@ -3,7 +3,6 @@ module Main (main) where
 | 
				
			||||||
import Control.Monad (void, when)
 | 
					import Control.Monad (void, when)
 | 
				
			||||||
import Data.Either
 | 
					import Data.Either
 | 
				
			||||||
import Data.List (foldl')
 | 
					import Data.List (foldl')
 | 
				
			||||||
import Data.Maybe (isJust)
 | 
					 | 
				
			||||||
import Data.Map qualified as M
 | 
					import Data.Map qualified as M
 | 
				
			||||||
import Data.Void (Void)
 | 
					import Data.Void (Void)
 | 
				
			||||||
import Text.Megaparsec
 | 
					import Text.Megaparsec
 | 
				
			||||||
| 
						 | 
					@ -70,11 +69,12 @@ compute (Input rules messages) = length . filter id $ map isValid messages
 | 
				
			||||||
      Just "" -> True
 | 
					      Just "" -> True
 | 
				
			||||||
      otherwise -> False
 | 
					      otherwise -> False
 | 
				
			||||||
    matches :: RuleID -> Message -> Maybe Message
 | 
					    matches :: RuleID -> Message -> Maybe Message
 | 
				
			||||||
 | 
					    matches _ [] = Nothing
 | 
				
			||||||
    matches ruleId msg = case rules M.! ruleId of
 | 
					    matches ruleId msg = case rules M.! ruleId of
 | 
				
			||||||
      Left c -> if head msg == c then (Just $ tail msg) else Nothing
 | 
					      Left c -> if head msg == c then (Just $ tail msg) else Nothing
 | 
				
			||||||
      Right actions -> case map (processAction msg) actions of
 | 
					      Right actions -> case map (processAction msg) actions of
 | 
				
			||||||
        Nothing:a:_ -> a
 | 
					        Just a:_ -> Just a
 | 
				
			||||||
        a:_ -> a
 | 
					        Nothing:Just a:_ -> Just a
 | 
				
			||||||
        otherwise -> Nothing
 | 
					        otherwise -> Nothing
 | 
				
			||||||
    processAction :: Message -> Action -> Maybe Message
 | 
					    processAction :: Message -> Action -> Maybe Message
 | 
				
			||||||
    processAction msg action = foldl' step (Just msg) action
 | 
					    processAction msg action = foldl' step (Just msg) action
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue