File: NonEmpty.hs

package info (click to toggle)
haskell-basement 0.0.16-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,044 kB
  • sloc: haskell: 11,336; ansic: 63; makefile: 2
file content (25 lines) | stat: -rw-r--r-- 670 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
-- |
-- Module      : Basement.NonEmpty
-- License     : BSD-style
-- Maintainer  : Foundation
-- Stability   : experimental
-- Portability : portable
--
-- A newtype wrapper around a non-empty Collection.

module Basement.NonEmpty
    ( NonEmpty(..)
    ) where

import           Basement.Exception
import           Basement.Compat.Base

-- | NonEmpty property for any Collection
newtype NonEmpty a = NonEmpty { getNonEmpty :: a }
    deriving (Show,Eq)

instance IsList c => IsList (NonEmpty c) where
    type Item (NonEmpty c) = Item c
    toList      = toList . getNonEmpty
    fromList [] = throw NonEmptyCollectionIsEmpty
    fromList l  = NonEmpty . fromList $ l