Module SList
This module is undocumented. This is a list of its definitions.
Cons :: a -> SList a -> SList a
allSList :: (a -> <b> Boolean) -> SList a -> <b> Boolean
Returns True if all elements of the list satisfy the given predicate. Stops at the first rejected element.
anySList :: (a -> <b> Boolean) -> SList a -> <b> Boolean
Returns True if at least one element of the list satisfies the given predicate. Stops at the first accepted element.
appendSList :: SList a -> SList a -> SList a
Creates a new list containing the elements of the first list followed by the elements of the second one.
dropSList :: Integer -> SList a -> SList a
dropSList n l returns l without its first n elements. The count comes
first and the list second, the opposite way round from nthSList.
The count is clamped and neither end fails: an n of zero or less returns the
whole list, an n larger than the length returns the empty list.
Example:
> l = SList.fromListSList [1, 2, 3]
> SList.toListSList (SList.dropSList 2 l)
[3]
> SList.dropSList 10 l
Nil
> SList.toListSList (SList.dropSList (-1) l)
[1, 2, 3]
foldl1SList :: (a -> a -> <b> a) -> SList a -> <b> a
Like foldlSList, but uses the first element of the list as the initial
value. The example computes (1 - 2) - 3.
Fails if the list is empty. The definition is a single non-exhaustive equation,
so the failure is a matching exception quoting the internal pattern rather than
a message about an empty list. Check with isEmptySList when the list may be
empty.
Example:
SList.foldl1SList (\accum x -> accum - x) (SList.fromListSList [1, 2, 3]) = -4
foldlSList :: (a -> b -> <c> a) -> a -> SList b -> <c> a
foldlSList f init l folds over the elements of l from left to right,
starting with init.
The accumulator is the first argument of f and the element the second,
the other way round from foldrSList. The example computes
((0 - 1) - 2) - 3.
Example:
SList.foldlSList (\accum x -> accum - x) 0 (SList.fromListSList [1, 2, 3]) = -6
foldrSList :: (a -> b -> <c> b) -> b -> SList a -> <c> b
foldrSList f init l folds over the elements of l from right to left,
starting with init.
The element is the first argument of f and the accumulator the second,
the other way round from foldlSList. The example computes
1 - (2 - (3 - 0)), where subtracting the same list from the left with
foldlSList gives -6.
Example:
SList.foldrSList (\x accum -> x - accum) 0 (SList.fromListSList [1, 2, 3]) = 2
fromListSList :: [a] -> SList a
Creates a list containing the elements of the given Prelude list, in the same order. See toListSList for an example of the round trip.
isEmptySList :: SList a -> Boolean
Returns True if the list contains no elements.
iterSList :: (a -> <c> b) -> SList a -> <c> ()
Calls the given function with all elements of the list.
lengthSList :: SList a -> Integer
The number of elements in the list.
mapFirstSList :: (a -> <c> Maybe b) -> SList a -> <c> Maybe b
Applies the given function to the elements of the list from the front until it
returns Just and returns that result. Returns Nothing if the function
returns Nothing for all elements.
Despite its Maybe-in, Maybe-out shape this is not a map: it is a combined
map and search that returns the first mapped value and never applies the
function to the elements after it.
Example:
> l = SList.fromListSList [1, 2, 3]
> SList.mapFirstSList (\x -> if x > 1 then Just (x * 10) else Nothing) l
Just 20
> SList.mapFirstSList (\x -> if x > 9 then Just (x * 10) else Nothing) l
Nothing
mapSList :: (a -> <c> b) -> SList a -> <c> SList b
Creates a new list containing the elements of the given list mapped with the
given function. The elements are visited from the front.
Example:
> l = SList.fromListSList [1, 2, 3]
> SList.toListSList (SList.mapSList (\x -> x * 10) l)
[10, 20, 30]
nthSList :: SList a -> Integer -> a
nthSList l i returns the element of l at the index i. Indexing starts
from zero. The list comes first and the index second, the opposite way round
from takeSList and dropSList.
Fails if the index is out of range; unlike takeSList and dropSList this one
does not clamp. The list is traversed from the front, so a call costs time
proportional to i.
Example:
> l = SList.fromListSList ["a", "b", "c"]
> SList.nthSList l 0
"a"
> SList.nthSList l 2
"c"
reverseSList :: SList a -> SList a
Creates a new list with the elements of the given list in reverse order.
singletonSList :: a -> SList a
Creates a list containing just the given element.
sortSList :: Ord a => SList a -> SList a
Sorts the elements of the list into ascending order with merge sort.
takeSList :: Integer -> SList a -> SList a
takeSList n l returns the first n elements of l. The count comes first
and the list second, the opposite way round from nthSList.
The count is clamped and neither end fails: an n of zero or less returns the
empty list, an n larger than the length returns the whole list.
Example:
> l = SList.fromListSList [1, 2, 3]
> SList.toListSList (SList.takeSList 2 l)
[1, 2]
> SList.toListSList (SList.takeSList 10 l)
[1, 2, 3]
> SList.takeSList 0 l
Nil
toListSList :: SList a -> [a]
The elements of the list as a Prelude list, in the same order. This is the
inverse of fromListSList and the readable way to print an SList.
Example:
SList.toListSList (SList.fromListSList [1, 2, 3]) = [1, 2, 3]
|