Skip to content

Commit

Permalink
Extract optics to access conflict bodies
Browse files Browse the repository at this point in the history
  • Loading branch information
yairchu committed Oct 1, 2020
1 parent 42f2673 commit 2bc99d0
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Conflict.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Conflict
( Conflict(..), LineNo
, bodyStrings, setBodyStrings
, bodies, setBodies, bodyStrings, setBodyStrings
, pretty, prettyLines
, parse
, markerPrefix
Expand All @@ -28,14 +28,20 @@ data Conflict = Conflict
} deriving (Show)

-- traversal
bodyStrings :: Applicative f => (String -> f String) -> Conflict -> f Conflict
bodyStrings f c@Conflict{..} =
mk <$> traverse f cBodyA <*> traverse f cBodyBase <*> traverse f cBodyB
bodies :: Applicative f => ([String] -> f [String]) -> Conflict -> f Conflict
bodies f c@Conflict{..} =
mk <$> f cBodyA <*> f cBodyBase <*> f cBodyB
where
mk bodyA bodyBase bodyB =
c{cBodyA=bodyA, cBodyBase=bodyBase, cBodyB=bodyB}

bodyStrings :: Applicative f => (String -> f String) -> Conflict -> f Conflict
bodyStrings = bodies . traverse

-- setter:
setBodies :: ([String] -> [String]) -> Conflict -> Conflict
setBodies f = runIdentity . bodies (Identity . f)

setBodyStrings :: (String -> String) -> Conflict -> Conflict
setBodyStrings f = runIdentity . bodyStrings (Identity . f)

Expand Down

0 comments on commit 2bc99d0

Please sign in to comment.