1
1
mirror of https://github.com/github/semantic.git synced 2024-12-25 16:02:43 +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 , lams
, unlam , unlam
, unseq , unseq
, unseqs
, ($$*) , ($$*)
, unapply , unapply
, unapplies , unapplies
@ -20,6 +21,7 @@ module Data.Core
import Control.Applicative (Alternative (..)) import Control.Applicative (Alternative (..))
import Control.Monad (ap) import Control.Monad (ap)
import Data.Foldable (foldl') import Data.Foldable (foldl')
import Data.List.NonEmpty
import Data.Loc import Data.Loc
import Data.Name import Data.Name
import Data.Stack import Data.Stack
@ -82,6 +84,12 @@ unseq :: Alternative m => Core a -> m (Core a, Core a)
unseq (a :>> b) = pure (a, b) unseq (a :>> b) = pure (a, b)
unseq _ = empty 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. -- | Application of a function to a sequence of arguments.
($$*) :: Foldable t => Core a -> t (Core a) -> Core a ($$*) :: Foldable t => Core a -> t (Core a) -> Core a
($$*) = foldl' (:$) ($$*) = foldl' (:$)