1
1
mirror of https://github.com/github/semantic.git synced 2024-12-22 14:21:31 +03:00

🔥 Both.unzip.

This commit is contained in:
Rob Rix 2016-04-04 16:25:16 -04:00
parent df4247d0c9
commit d2beafdc84
3 changed files with 2 additions and 6 deletions

View File

@ -23,7 +23,7 @@ import Data.Bifunctor.These
import Data.Coalescent import Data.Coalescent
import Data.Copointed import Data.Copointed
import Data.Foldable import Data.Foldable
import Data.Functor.Both as Both hiding (unzip) import Data.Functor.Both as Both
import Data.Functor.Identity import Data.Functor.Identity
import Data.Maybe import Data.Maybe
import Data.Monoid import Data.Monoid

View File

@ -42,10 +42,6 @@ fst = Prelude.fst . runBoth
snd :: Both a -> a snd :: Both a -> a
snd = Prelude.snd . runBoth snd = Prelude.snd . runBoth
unzip :: [Both a] -> Both [a]
unzip = foldr pair (pure [])
where pair head tail = (:) <$> head <*> tail
instance Monoid a => Monoid (Join (,) a) where instance Monoid a => Monoid (Join (,) a) where
mempty = pure mempty mempty = pure mempty
mappend a b = mappend <$> a <*> b mappend a b = mappend <$> a <*> b

View File

@ -65,7 +65,7 @@ showHunk blobs hunk = maybeOffsetHeader ++
-- | Given the before and after sources, render a change to a string. -- | Given the before and after sources, render a change to a string.
showChange :: Both (Source Char) -> Change (SplitDiff a Info) -> String showChange :: Both (Source Char) -> Change (SplitDiff a Info) -> String
showChange sources change = showLines (snd sources) ' ' (snd <$> context change) ++ deleted ++ inserted showChange sources change = showLines (snd sources) ' ' (snd <$> context change) ++ deleted ++ inserted
where (deleted, inserted) = runBoth $ pure showLines <*> sources <*> both '-' '+' <*> Both.unzip (contents change) where (deleted, inserted) = runBoth $ pure showLines <*> sources <*> both '-' '+' <*> Join (unzip (runJoin <$> contents change))
-- | Given a source, render a set of lines to a string with a prefix. -- | Given a source, render a set of lines to a string with a prefix.
showLines :: Source Char -> Char -> [Line (SplitDiff leaf Info)] -> String showLines :: Source Char -> Char -> [Line (SplitDiff leaf Info)] -> String