Skip to content

Commit

Permalink
Add NonEmpty wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
UnkindPartition committed Jul 12, 2013
1 parent 37a8a0c commit 22f1169
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Test/SmallCheck/Series.hs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ module Test.SmallCheck.Series (
Depth, Series, Serial(..), CoSerial(..),

-- * Convenient wrappers
Positive(..), NonNegative(..),
Positive(..), NonNegative(..), NonEmpty(..),

-- * Other useful definitions
(\/), (><), (<~>), (>>-),
Expand Down Expand Up @@ -606,4 +606,13 @@ instance (Num a, Ord a, Serial m a) => Serial m (NonNegative a) where
instance Show a => Show (NonNegative a) where
showsPrec n (NonNegative x) = showsPrec n x

-- | @NonEmpty xs@: guarantees that @xs@ is not null
newtype NonEmpty a = NonEmpty { getNonEmpty :: [a] }

instance (Serial m a) => Serial m (NonEmpty a) where
series = NonEmpty <$> cons2 (:)

instance Show a => Show (NonEmpty a) where
showsPrec n (NonEmpty x) = showsPrec n x

-- }}}

0 comments on commit 22f1169

Please sign in to comment.