slist-0.2.0.0: Sized list
Copyright(c) 2021 Kowainik
LicenseMPL-2.0
MaintainerKowainik <xrom.xkov@gmail.com>
StabilityStable
PortabilityPortable
Safe HaskellNone
LanguageHaskell2010

Slist.Type

Description

The main Slist data types and instances. Provides smart constructors and a few basic functions.

Synopsis

Documentation

data Slist a Source #

Data type that represents sized list. Size can be both finite or infinite, it is established using Size data type.

Constructors

Slist 

Fields

Instances

Instances details
Monad Slist Source # 
Instance details

Defined in Slist.Type

Methods

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

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

return :: a -> Slist a #

Functor Slist Source # 
Instance details

Defined in Slist.Type

Methods

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

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

Applicative Slist Source # 
Instance details

Defined in Slist.Type

Methods

pure :: a -> Slist a #

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

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

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

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

Foldable Slist Source #

Efficient implementation of sum and product functions. length returns Ints maxBound on infinite lists.

Instance details

Defined in Slist.Type

Methods

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

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

foldMap' :: Monoid m => (a -> m) -> Slist a -> m #

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

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

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

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

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

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

toList :: Slist a -> [a] #

null :: Slist a -> Bool #

length :: Slist a -> Int #

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

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

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

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

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

Traversable Slist Source # 
Instance details

Defined in Slist.Type

Methods

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

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

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

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

Alternative Slist Source # 
Instance details

Defined in Slist.Type

Methods

empty :: Slist a #

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

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

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

IsList (Slist a) Source # 
Instance details

Defined in Slist.Type

Associated Types

type Item (Slist a) #

Methods

fromList :: [Item (Slist a)] -> Slist a #

fromListN :: Int -> [Item (Slist a)] -> Slist a #

toList :: Slist a -> [Item (Slist a)] #

Eq a => Eq (Slist a) Source #

Equality of sized lists is checked more efficiently due to the fact that the check on the list sizes can be done first for the constant time.

Instance details

Defined in Slist.Type

Methods

(==) :: Slist a -> Slist a -> Bool #

(/=) :: Slist a -> Slist a -> Bool #

Ord a => Ord (Slist a) Source #

Lexicographical comparison of the lists.

Instance details

Defined in Slist.Type

Methods

compare :: Slist a -> Slist a -> Ordering #

(<) :: Slist a -> Slist a -> Bool #

(<=) :: Slist a -> Slist a -> Bool #

(>) :: Slist a -> Slist a -> Bool #

(>=) :: Slist a -> Slist a -> Bool #

max :: Slist a -> Slist a -> Slist a #

min :: Slist a -> Slist a -> Slist a #

Read a => Read (Slist a) Source # 
Instance details

Defined in Slist.Type

Show a => Show (Slist a) Source # 
Instance details

Defined in Slist.Type

Methods

showsPrec :: Int -> Slist a -> ShowS #

show :: Slist a -> String #

showList :: [Slist a] -> ShowS #

Semigroup (Slist a) Source #

List appending. Use <> for Slist concatenation instead of ++ operator that is common in ordinary list concatenations.

Instance details

Defined in Slist.Type

Methods

(<>) :: Slist a -> Slist a -> Slist a #

sconcat :: NonEmpty (Slist a) -> Slist a #

stimes :: Integral b => b -> Slist a -> Slist a #

Monoid (Slist a) Source # 
Instance details

Defined in Slist.Type

Methods

mempty :: Slist a #

mappend :: Slist a -> Slist a -> Slist a #

mconcat :: [Slist a] -> Slist a #

type Item (Slist a) Source # 
Instance details

Defined in Slist.Type

type Item (Slist a) = a

Smart constructors

slist :: [a] -> Slist a Source #

O(n). Constructs Slist from the given list.

>>> slist [1..5]
Slist {sList = [1,2,3,4,5], sSize = Size 5}

Note: works with finite lists. Use infiniteSlist to construct infinite lists.

infiniteSlist :: [a] -> Slist a Source #

O(1). Constructs Slist from the given list.

>> infiniteSlist [1..]
Slist {sList = [1..], sSize = Infinity}

Note: works with infinite lists. Use slist to construct finite lists.

one :: a -> Slist a Source #

O(1). Creates Slist with a single element. The size of such Slist is always equals to Size 1.

>>> one "and only"
Slist {sList = ["and only"], sSize = Size 1}

Basic functions

len :: Slist a -> Int Source #

O(1). Returns the length of a structure as an Int. On infinite lists returns the Ints maxBound.

>>> len $ one 42
1
>>> len $ slist [1..3]
3
>>> len $ infiniteSlist [1..]
9223372036854775807

size :: Slist a -> Size Source #

O(1). Returns the Size of the slist.

>>> size $ slist "Hello World!"
Size 12
>>> size $ infiniteSlist [1..]
Infinity

isEmpty :: Slist a -> Bool Source #

O(1). Checks if Slist is empty

>>> isEmpty mempty
True
>>> isEmpty $ slist []
True
>>> isEmpty $ slist "Not Empty"
False

cons :: a -> Slist a -> Slist a Source #

O(1). cons is Slist analogue to : for lists. It adds the given element to the beginning of the list.

The following property is preserved:

  size (cons x xs) == size xs + 1

Examples:

>>> cons 'a' $ one 'b'
Slist {sList = "ab", sSize = Size 2}
>> cons 0 $ infiniteSlist [1..]
Slist {sList = [0..], sSize = Infinity}

map :: (a -> b) -> Slist a -> Slist b Source #

O(n). Applies the given function to each element of the slist.

map f (slist [x1, x2, ..., xn])     == slist [f x1, f x2, ..., f xn]
map f (infiniteSlist [x1, x2, ...]) == infiniteSlist [f x1, f x2, ...]