toy-lib-0.1.0.0
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.SafeList

Description

Safe, total functions.

Synopsis

Documentation

class SafeList v where #

Safelist

Associated Types

type SafeListElem v #

Instances

Instances details
Ord a => SafeList (Vector a) #

Tests

>>> headMay $ V.fromList ([] :: [Int])
Nothing
>>> headMay $ V.fromList ([1, 2, 3] :: [Int])
Just 1
>>> lastMay $ V.fromList ([] :: [Int])
Nothing
>>> lastMay $ V.fromList ([1, 2, 3] :: [Int])
Just 3
>>> headOr (-1) $ V.fromList ([] :: [Int])
-1
>>> headOr (-1) $ V.fromList ([1, 2, 3] :: [Int])
1
>>> lastOr (-1) $ V.fromList ([] :: [Int])
-1
>>> lastOr (-1) $ V.fromList ([1, 2, 3] :: [Int])
3
>>> minimumMay $ V.fromList ([] :: [Int])
Nothing
>>> minimumMay $ V.fromList ([2, 1, 4, 3] :: [Int])
Just 1
>>> maximumMay $ V.fromList ([] :: [Int])
Nothing
>>> maximumMay $ V.fromList ([2, 1, 4, 3] :: [Int])
Just 4
>>> minimumOr (-1) $ V.fromList ([] :: [Int])
-1
>>> minimumOr (-1) $ V.fromList ([2, 1, 4, 3] :: [Int])
1
>>> maximumOr (-1) $ V.fromList ([] :: [Int])
-1
>>> maximumOr (-1) $ V.fromList ([2, 1, 4, 3] :: [Int])
4
Instance details

Defined in Data.SafeList

Associated Types

type SafeListElem (Vector a) #

(Unbox a, Ord a) => SafeList (Vector a) #

The implementation is same as the one for Vector.

Instance details

Defined in Data.SafeList

Associated Types

type SafeListElem (Vector a) #

Ord a => SafeList [a] #

Tests

>>> headMay ([] :: [Int])
Nothing
>>> headMay ([1, 2, 3] :: [Int])
Just 1
>>> lastMay ([] :: [Int])
Nothing
>>> lastMay ([1, 2, 3] :: [Int])
Just 3
>>> headOr (-1) ([] :: [Int])
-1
>>> headOr (-1) ([1, 2, 3] :: [Int])
1
>>> lastOr (-1) ([] :: [Int])
-1
>>> lastOr (-1) ([1, 2, 3] :: [Int])
3
>>> minimumMay ([] :: [Int])
Nothing
>>> minimumMay ([2, 1, 4, 3] :: [Int])
Just 1
>>> maximumMay ([] :: [Int])
Nothing
>>> maximumMay ([2, 1, 4, 3] :: [Int])
Just 4
>>> minimumOr (-1) ([] :: [Int])
-1
>>> minimumOr (-1) ([2, 1, 4, 3] :: [Int])
1
>>> maximumOr (-1) ([] :: [Int])
-1
>>> maximumOr (-1) ([2, 1, 4, 3] :: [Int])
4
Instance details

Defined in Data.SafeList

Associated Types

type SafeListElem [a] #

Methods

headMay :: [a] -> Maybe (SafeListElem [a]) #

lastMay :: [a] -> Maybe (SafeListElem [a]) #

headOr :: SafeListElem [a] -> [a] -> SafeListElem [a] #

lastOr :: SafeListElem [a] -> [a] -> SafeListElem [a] #

minimumMay :: [a] -> Maybe (SafeListElem [a]) #

maximumMay :: [a] -> Maybe (SafeListElem [a]) #

minimumOr :: SafeListElem [a] -> [a] -> SafeListElem [a] #

maximumOr :: SafeListElem [a] -> [a] -> SafeListElem [a] #