1
1
mirror of https://github.com/github/semantic.git synced 2024-12-24 23:42:31 +03:00

Decompose sequences deeply.

This commit is contained in:
Rob Rix 2019-06-26 08:41:25 -04:00
parent 4b11270791
commit 6e5d4baa5f
No known key found for this signature in database
GPG Key ID: F188A01508EA1CF7

View File

@ -7,6 +7,7 @@ module Data.Core
, lams
, unlam
, unseq
, unseqs
, ($$*)
, unapply
, unapplies
@ -20,6 +21,7 @@ module Data.Core
import Control.Applicative (Alternative (..))
import Control.Monad (ap)
import Data.Foldable (foldl')
import Data.List.NonEmpty
import Data.Loc
import Data.Name
import Data.Stack
@ -82,6 +84,12 @@ unseq :: Alternative m => Core a -> m (Core a, Core a)
unseq (a :>> b) = pure (a, b)
unseq _ = empty
unseqs :: Core a -> NonEmpty (Core a)
unseqs = go
where go t = case unseq t of
Just (l, r) -> go l <> go r
Nothing -> t :| []
-- | Application of a function to a sequence of arguments.
($$*) :: Foldable t => Core a -> t (Core a) -> Core a
($$*) = foldl' (:$)