htssets-0.2.0.0: Heterogenous Sets

Copyright(c) Zoltan Kelemen 2017
LicenseBSD-style
Maintainerkelemzol@elte.hu
Safe HaskellNone
LanguageHaskell2010

Data.HtsCSet

Description

HtsCSet is a Heterogenous Set wich can provide storing values with different and constrained type.

These modules are intended to be imported qualified, to avoid name clashes with Prelude functions, e.g.

 import qualified Data.HtsCSet as HCSet
Synopsis

Documentation

empty :: HtsCSet c Source #

The empty HtsCSet

emptyP :: proxy c -> HtsCSet c Source #

The empty HtsCSet with proxy

singleton :: forall c a. (Typeable a, c a) => a -> HtsCSet c Source #

A HtsCSet with an element

singletonP :: forall proxy c a. (Typeable a, c a) => proxy c -> a -> HtsCSet c Source #

A HtsCSet with an element with proxy

null :: HtsCSet c -> Bool Source #

Is the HtsCSet is empty?

null empty == True
null (singleton "a") == False

size :: HtsCSet c -> Int Source #

The number of elements in the HtsSet

size empty == 0
size (singleton "a") == 1

member :: forall proxy c a. (Typeable a, Eq a, c a) => a -> HtsCSet c -> Bool Source #

The HtsSet is contain an element?

member (Proxy :: Proxy String) empty == False
member (Proxy :: Proxy String) (singleton "a") == True

notMember :: forall proxy c a. (Typeable a, Eq a, c a) => a -> HtsCSet c -> Bool Source #

The HtsSet is not contain an element?

existTypeOf :: forall c a. (Typeable a, c a) => a -> HtsCSet c -> Bool Source #

The HtsCSet is contain a same type of element?

let hs = insert "a" $ insert (2 :: Int) $ insert 'c' $ empty
existTypeOf "string" hs == True

existTypeOfP :: forall proxy c a. (Typeable a, c a) => proxy a -> HtsCSet c -> Bool Source #

The HtsCSet is contain a same type of element? (by proxy)

existTypeOfP' :: forall c a. (Typeable a, c a) => Proxy a -> HtsCSet c -> Bool Source #

The HtsCSet is contain a same type of element? (by fixed proxy)

appl :: forall a b c. (Typeable a, c a) => b -> (a -> b) -> HtsCSet c -> b Source #

Apply a function to an element with a default value

appl "no ABC" (:"BC") $ singleton 'A' == "ABC"
appl "no ABC" (:"BC") $ singleton "s" == "no ABC"

compliance :: forall a c. (Typeable a, c a) => Bool -> (a -> Bool) -> HtsCSet c -> Bool Source #

appl specialization

insert :: forall c a. (Typeable a, c a) => a -> HtsCSet c -> HtsCSet c Source #

Insert a new value in the HtsCSet. If the a elem is already present in the HtsCSet with type, the associated value is replaced with the supplied value

insert "a" $ insert (2 :: Int) $ insert 'c' $ empty

lookup :: forall c a. (Typeable a, c a) => HtsCSet c -> Maybe a Source #

Lookup a value from in the HtsCSet

let hs = insert "a" $ insert (2 :: Int) $ insert 'c' $ empty
lookup hs == Just "a"
lookup hs == Just (2 :: Int)
but
lookup hs == Just 2 -- is False! Because the type of 2 is Num t => t not Int

lookupWithDefault :: forall c a. (Typeable a, c a) => a -> HtsCSet c -> a Source #

Lookup a value from in the HtsCSet with a default value

update :: forall c a. (Typeable a, c a) => (a -> a) -> HtsCSet c -> HtsCSet c Source #

Update a value in HtsCSet

let hs = insert "a" $ insert (2 :: Int) $ insert 'c' $ empty
let hs' = update (++"b") hs
lookup hs' == Just "ab"

deleteByType :: forall a c. (Typeable a, c a) => a -> HtsCSet c -> HtsCSet c Source #

Delete an element by type

(member 'c' $ deleteByType 'b' $ singleton 'c') == False

deleteByTypeP :: forall proxy c a. (Typeable a, c a) => proxy a -> HtsCSet c -> HtsCSet c Source #

Delete an element by type (by proxy)

(member 'c' $ deleteByTypeP (Proxy :: Proxy Char) $ singleton 'c') == False

deleteByTypeP' :: forall a c. (Typeable a, c a) => Proxy a -> HtsCSet c -> HtsCSet c Source #

Delete an element by type (by fixed proxy)

deleteWhen :: forall a c. (Typeable a, c a) => (a -> Bool) -> HtsCSet c -> HtsCSet c Source #

Delete an element by condition

data a :+ b infixr 5 Source #

Helper heterogeneous list for comfortable HtsSet building (with append and fill)

let hs = fill ("a" :+ 'c' :+ True :+ ())
lookup (hs :: HtsCSet Show) == Just 'c'
use () to close the list
lookup (hs :: HtsCSet Show) == Just () -- is False!
let hs' = fill ("a" :+ 'c' :+ True :+ () :+ ())
lookup (hs' :: HtsCSet Show) == Just () -- is Ok

Constructors

a :+ b infixr 5 
Instances
(Typeable a, c a, Append c b) => Append c (a :+ b) Source # 
Instance details

Defined in Data.HtsCSet

Methods

append :: (a :+ b) -> HtsCSet c -> HtsCSet c Source #

class Append c a where Source #

Methods

append :: a -> HtsCSet c -> HtsCSet c Source #

Instances
Append c () Source # 
Instance details

Defined in Data.HtsCSet

Methods

append :: () -> HtsCSet c -> HtsCSet c Source #

(Typeable a, c a, Append c b) => Append c (a :+ b) Source # 
Instance details

Defined in Data.HtsCSet

Methods

append :: (a :+ b) -> HtsCSet c -> HtsCSet c Source #

fill :: Append c a => a -> HtsCSet c Source #

data Proxy (t :: k) :: forall k. k -> Type #

Proxy is a type that holds no data, but has a phantom parameter of arbitrary type (or even kind). Its use is to provide type information, even though there is no value available of that type (or it may be too costly to create one).

Historically, Proxy :: Proxy a is a safer alternative to the 'undefined :: a' idiom.

>>> Proxy :: Proxy (Void, Int -> Int)
Proxy

Proxy can even hold types of higher kinds,

>>> Proxy :: Proxy Either
Proxy
>>> Proxy :: Proxy Functor
Proxy
>>> Proxy :: Proxy complicatedStructure
Proxy

Constructors

Proxy 
Instances
Monad (Proxy :: Type -> Type)

Since: base-4.7.0.0

Instance details

Defined in Data.Proxy

Methods

(>>=) :: Proxy a -> (a -> Proxy b) -> Proxy b #

(>>) :: Proxy a -> Proxy b -> Proxy b #

return :: a -> Proxy a #

fail :: String -> Proxy a #

Functor (Proxy :: Type -> Type)

Since: base-4.7.0.0

Instance details

Defined in Data.Proxy

Methods

fmap :: (a -> b) -> Proxy a -> Proxy b #

(<$) :: a -> Proxy b -> Proxy a #

Applicative (Proxy :: Type -> Type)

Since: base-4.7.0.0

Instance details

Defined in Data.Proxy

Methods

pure :: a -> Proxy a #

(<*>) :: Proxy (a -> b) -> Proxy a -> Proxy b #

liftA2 :: (a -> b -> c) -> Proxy a -> Proxy b -> Proxy c #

(*>) :: Proxy a -> Proxy b -> Proxy b #

(<*) :: Proxy a -> Proxy b -> Proxy a #

Foldable (Proxy :: Type -> Type)

Since: base-4.7.0.0

Instance details

Defined in Data.Foldable

Methods

fold :: Monoid m => Proxy m -> m #

foldMap :: Monoid m => (a -> m) -> Proxy a -> m #

foldr :: (a -> b -> b) -> b -> Proxy a -> b #

foldr' :: (a -> b -> b) -> b -> Proxy a -> b #

foldl :: (b -> a -> b) -> b -> Proxy a -> b #

foldl' :: (b -> a -> b) -> b -> Proxy a -> b #

foldr1 :: (a -> a -> a) -> Proxy a -> a #

foldl1 :: (a -> a -> a) -> Proxy a -> a #

toList :: Proxy a -> [a] #

null :: Proxy a -> Bool #

length :: Proxy a -> Int #

elem :: Eq a => a -> Proxy a -> Bool #

maximum :: Ord a => Proxy a -> a #

minimum :: Ord a => Proxy a -> a #

sum :: Num a => Proxy a -> a #

product :: Num a => Proxy a -> a #

Traversable (Proxy :: Type -> Type)

Since: base-4.7.0.0

Instance details

Defined in Data.Traversable

Methods

traverse :: Applicative f => (a -> f b) -> Proxy a -> f (Proxy b) #

sequenceA :: Applicative f => Proxy (f a) -> f (Proxy a) #

mapM :: Monad m => (a -> m b) -> Proxy a -> m (Proxy b) #

sequence :: Monad m => Proxy (m a) -> m (Proxy a) #

Alternative (Proxy :: Type -> Type)

Since: base-4.9.0.0

Instance details

Defined in Data.Proxy

Methods

empty :: Proxy a #

(<|>) :: Proxy a -> Proxy a -> Proxy a #

some :: Proxy a -> Proxy [a] #

many :: Proxy a -> Proxy [a] #

MonadPlus (Proxy :: Type -> Type)

Since: base-4.9.0.0

Instance details

Defined in Data.Proxy

Methods

mzero :: Proxy a #

mplus :: Proxy a -> Proxy a -> Proxy a #

Bounded (Proxy t)

Since: base-4.7.0.0

Instance details

Defined in Data.Proxy

Methods

minBound :: Proxy t #

maxBound :: Proxy t #

Enum (Proxy s)

Since: base-4.7.0.0

Instance details

Defined in Data.Proxy

Methods

succ :: Proxy s -> Proxy s #

pred :: Proxy s -> Proxy s #

toEnum :: Int -> Proxy s #

fromEnum :: Proxy s -> Int #

enumFrom :: Proxy s -> [Proxy s] #

enumFromThen :: Proxy s -> Proxy s -> [Proxy s] #

enumFromTo :: Proxy s -> Proxy s -> [Proxy s] #

enumFromThenTo :: Proxy s -> Proxy s -> Proxy s -> [Proxy s] #

Eq (Proxy s)

Since: base-4.7.0.0

Instance details

Defined in Data.Proxy

Methods

(==) :: Proxy s -> Proxy s -> Bool #

(/=) :: Proxy s -> Proxy s -> Bool #

Ord (Proxy s)

Since: base-4.7.0.0

Instance details

Defined in Data.Proxy

Methods

compare :: Proxy s -> Proxy s -> Ordering #

(<) :: Proxy s -> Proxy s -> Bool #

(<=) :: Proxy s -> Proxy s -> Bool #

(>) :: Proxy s -> Proxy s -> Bool #

(>=) :: Proxy s -> Proxy s -> Bool #

max :: Proxy s -> Proxy s -> Proxy s #

min :: Proxy s -> Proxy s -> Proxy s #

Read (Proxy t)

Since: base-4.7.0.0

Instance details

Defined in Data.Proxy

Show (Proxy s)

Since: base-4.7.0.0

Instance details

Defined in Data.Proxy

Methods

showsPrec :: Int -> Proxy s -> ShowS #

show :: Proxy s -> String #

showList :: [Proxy s] -> ShowS #

Ix (Proxy s)

Since: base-4.7.0.0

Instance details

Defined in Data.Proxy

Methods

range :: (Proxy s, Proxy s) -> [Proxy s] #

index :: (Proxy s, Proxy s) -> Proxy s -> Int #

unsafeIndex :: (Proxy s, Proxy s) -> Proxy s -> Int

inRange :: (Proxy s, Proxy s) -> Proxy s -> Bool #

rangeSize :: (Proxy s, Proxy s) -> Int #

unsafeRangeSize :: (Proxy s, Proxy s) -> Int

Semigroup (Proxy s)

Since: base-4.9.0.0

Instance details

Defined in Data.Proxy

Methods

(<>) :: Proxy s -> Proxy s -> Proxy s #

sconcat :: NonEmpty (Proxy s) -> Proxy s #

stimes :: Integral b => b -> Proxy s -> Proxy s #

Monoid (Proxy s)

Since: base-4.7.0.0

Instance details

Defined in Data.Proxy

Methods

mempty :: Proxy s #

mappend :: Proxy s -> Proxy s -> Proxy s #

mconcat :: [Proxy s] -> Proxy s #