mirror of
https://github.com/github/semantic.git
synced 2024-12-01 09:15:01 +03:00
Define beforeTerm via mergeMaybe.
This commit is contained in:
parent
8f7307c989
commit
8fcbaa3a7e
@ -41,11 +41,4 @@ mergeMaybe transform = cata algebra . fmap transform
|
||||
Keyed i -> Keyed (Map.fromList (Map.toList i >>= (\ (k, v) -> maybe [] (pure . (,) k) v)))
|
||||
|
||||
beforeTerm :: Diff leaf annotation -> Maybe (Term leaf annotation)
|
||||
beforeTerm = cata algebra
|
||||
where algebra :: FreeF (CofreeF (Syntax leaf) (Both annotation)) (Patch (Term leaf annotation)) (Maybe (Term leaf annotation)) -> Maybe (Term leaf annotation)
|
||||
algebra (Pure patch) = before patch
|
||||
algebra (Free (annotations :< syntax)) = Just . cofree $ Both.fst annotations :< case syntax of
|
||||
Leaf s -> Leaf s
|
||||
Indexed i -> Indexed (catMaybes i)
|
||||
Fixed i -> Fixed (catMaybes i)
|
||||
Keyed i -> Keyed (Map.fromList (Map.toList i >>= (\ (k, v) -> maybe [] (pure . (,) k) v)))
|
||||
beforeTerm = mergeMaybe before
|
||||
|
Loading…
Reference in New Issue
Block a user