1-- |
2-- Module      : Basement.NonEmpty
3-- License     : BSD-style
4-- Maintainer  : Foundation
5-- Stability   : experimental
6-- Portability : portable
7--
8-- A newtype wrapper around a non-empty Collection.
9
10module Basement.NonEmpty
11    ( NonEmpty(..)
12    ) where
13
14import           Basement.Exception
15import           Basement.Compat.Base
16
17-- | NonEmpty property for any Collection
18newtype NonEmpty a = NonEmpty { getNonEmpty :: a }
19    deriving (Show,Eq)
20
21instance IsList c => IsList (NonEmpty c) where
22    type Item (NonEmpty c) = Item c
23    toList      = toList . getNonEmpty
24    fromList [] = throw NonEmptyCollectionIsEmpty
25    fromList l  = NonEmpty . fromList $ l
26