mirror of
https://github.com/github/semantic.git
synced 2024-12-19 04:41:47 +03:00
Define an until combinator.
This commit is contained in:
parent
8d7fb65a4a
commit
2bc2483af9
@ -76,6 +76,7 @@ module Data.Syntax.Assignment
|
||||
, source
|
||||
, children
|
||||
, while
|
||||
, until
|
||||
-- Results
|
||||
, Error(..)
|
||||
, nodeError
|
||||
@ -114,7 +115,7 @@ import Data.Semigroup
|
||||
import qualified Data.Source as Source (Source, fromBytes, slice, sourceBytes, sourceLines)
|
||||
import GHC.Stack
|
||||
import qualified Info
|
||||
import Prelude hiding (head)
|
||||
import Prelude hiding (head, until)
|
||||
import System.Console.ANSI
|
||||
import Text.Parser.TreeSitter.Language
|
||||
|
||||
@ -168,6 +169,13 @@ while predicate step = many $ do
|
||||
guard (predicate result)
|
||||
pure result
|
||||
|
||||
-- | Collect a list of values failing a predicate.
|
||||
until :: (Alternative m, Monad m) => (a -> Bool) -> m a -> m [a]
|
||||
until predicate step = many $ do
|
||||
result <- step
|
||||
guard (not (predicate result))
|
||||
pure result
|
||||
|
||||
|
||||
-- | A location specified as possibly-empty intervals of bytes and line/column positions.
|
||||
type Location = '[Info.Range, Info.Span]
|
||||
|
Loading…
Reference in New Issue
Block a user