Skip to content

Commit

Permalink
Add pattern synonyms for IsSequence
Browse files Browse the repository at this point in the history
  • Loading branch information
vigress8 committed Jan 7, 2025
1 parent a4e71e7 commit b35023b
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions classy-prelude/src/ClassyPrelude.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ViewPatterns #-}

module ClassyPrelude
( -- * CorePrelude
module CorePrelude
Expand Down Expand Up @@ -129,6 +132,9 @@ module ClassyPrelude
, DList
, asDList
, applyDList
-- ** Pattern synonyms for sequences
, pattern Empty
, pattern Cons
-- ** Exceptions
, module Control.DeepSeq
-- ** Force types
Expand Down Expand Up @@ -627,6 +633,18 @@ getContents = liftIO LTextIO.getContents
interact :: MonadIO m => (LText -> LText) -> m ()
interact = liftIO . LTextIO.interact

-- | Pattern synonyms for working with sequences,
-- corresponding to [] and (x : xs) for List
--
-- @since 1.5.1
{-# COMPLETE Empty, Cons #-}
pattern Empty :: IsSequence seq => seq
pattern Empty <- (uncons -> Nothing) where
Empty = fromList []

pattern Cons :: IsSequence seq => Element seq -> seq -> seq
pattern Cons x xs <- (uncons -> Just (x, xs)) where
Cons = cons

#if MIN_VERSION_time(1,10,0)
parseTime
Expand Down

0 comments on commit b35023b

Please sign in to comment.