Initial commit
This commit is contained in:
commit
c101616e62
309 changed files with 53937 additions and 0 deletions
30
bundled/Basement/NonEmpty.hs
Normal file
30
bundled/Basement/NonEmpty.hs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
{-# LANGUAGE BangPatterns #-}
|
||||
{-# LANGUAGE DeriveDataTypeable #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
{-# LANGUAGE RebindableSyntax #-}
|
||||
{-# LANGUAGE NoImplicitPrelude #-}
|
||||
-- |
|
||||
-- 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue