In cases where a method takes arguments, these precede the
collection argument in the haskell variant, so that c.m(i,j)
becomes m i j c
.
- fill :: Int -> (Int -> a) -> [a]
- size :: [a] -> Int
- isEmpty :: [a] -> Bool
- ignoringIndex :: (a -> b) -> a -> Int -> b
- collect :: (a -> Int -> b) -> [a] -> [b]
- select :: (a -> Int -> Bool) -> [a] -> [a]
- reject :: (a -> Int -> Bool) -> [a] -> [a]
- detect :: (a -> Int -> Bool) -> [a] -> Maybe a
- detectIndex :: (a -> Int -> Bool) -> [a] -> Maybe Int
- inject :: a -> (a -> b -> a) -> [b] -> a
- any' :: (a -> Int -> Bool) -> [a] -> Bool
- every :: (a -> Int -> Bool) -> [a] -> Bool
- count :: (a -> Int -> Bool) -> [a] -> Int
- occurencesOf :: Eq a => a -> [a] -> Int
- sum' :: Num a => (b -> Int -> a) -> [b] -> a
- maxItem :: Ord b => (a -> Int -> b) -> [a] -> b
- minItem :: Ord b => (a -> Int -> b) -> [a] -> b
- zipWith_c :: (a -> b -> c) -> [a] -> [b] -> [c]
- zip_c :: [a] -> [b] -> [(a, b)]
- zipWith3_c :: (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d]
- zip3_c :: [a] -> [b] -> [c] -> [(a, b, c)]
- zap_c :: [a -> b] -> [a] -> [b]
- series :: Num a => Int -> a -> a -> [a]
- geom :: Num a => Int -> a -> a -> [a]
- fib :: Num a => Int -> a -> a -> [a]
- first :: [t] -> Maybe t
- first' :: [t] -> t
- lastM :: [t] -> Maybe t
- last :: [t] -> Maybe t
- last' :: [t] -> t
- indexOf :: Eq a => [a] -> a -> Maybe Int
- indexOf' :: Eq a => [a] -> a -> Int
- indexOfEqual :: Eq a => [a] -> a -> Maybe Int
- indexOfGreaterThan :: Ord a => a -> [a] -> Maybe Int
- indexIn :: (Ord a, Num a) => a -> [a] -> Int
- indexInBetween :: (Ord a, Fractional a) => a -> [a] -> a
- keep :: Int -> [a] -> [a]
- drop :: Int -> [a] -> [a]
- extension :: [[a]] -> [()]
- flop :: [[a]] -> [[a]]
- lace :: Int -> [[a]] -> [a]
- wrapExtend :: Int -> [a] -> [a]
- cycleFold :: [a] -> [a]
- foldExtend :: Int -> [a] -> [a]
- clipExtend :: Int -> [a] -> [a]
- cycleClip :: [a] -> [a]
- extendSequences :: [[a]] -> [[a]]
- separateAt :: (a -> a -> Bool) -> [a] -> ([a], [a])
- separate :: (a -> a -> Bool) -> [a] -> [[a]]
- clump :: Int -> [a] -> [[a]]
- clumps :: [Int] -> [a] -> [[a]]
- integrate :: Num a => [a] -> [a]
- differentiate :: Num a => [a] -> [a]
- rotateLeft :: Int -> [a] -> [a]
- rotateRight :: Int -> [a] -> [a]
- normalizeSum :: Fractional a => [a] -> [a]
- slide :: Int -> Int -> [a] -> [a]
- mirror :: [a] -> [a]
- mirror1 :: [a] -> [a]
- mirror2 :: [a] -> [a]
- stutter :: Int -> [a] -> [a]
- rotate :: Int -> [a] -> [a]
Collection
fill :: Int -> (Int -> a) -> [a]Source
Collection.*fill
is map
over indices to n.
fill 4 (* 2) == [0,2,4,6]
ignoringIndex :: (a -> b) -> a -> Int -> bSource
Function equal to const
of f of e.
select (ignoringIndex even) [1,2,3,4] == [2,4]
collect :: (a -> Int -> b) -> [a] -> [b]Source
Collection.collect
is map
with element indices.
collect (\i _ -> i + 10) [1,2,3,4] == [11,12,13,14] collect (\_ j -> j + 11) [1,2,3,4] == [11,12,13,14]
select :: (a -> Int -> Bool) -> [a] -> [a]Source
Collection.select
is filter
with element indices.
select (\i _ -> even i) [1,2,3,4] == [2,4] select (\_ j -> even j) [1,2,3,4] == [1,3]
reject :: (a -> Int -> Bool) -> [a] -> [a]Source
Collection.reject
is negated filter
with element indices.
reject (\i _ -> even i) [1,2,3,4] == [1,3] reject (\_ j -> even j) [1,2,3,4] == [2,4]
detectIndex :: (a -> Int -> Bool) -> [a] -> Maybe IntSource
Collection.detectIndex
is the index locating variant of detect
.
detectIndex (\i _ -> even i) [1,2,3,4] == Just 1
inject :: a -> (a -> b -> a) -> [b] -> aSource
Collection.inject
is a variant on foldl
.
inject 0 (+) [1..5] == 15 inject 1 (*) [1..5] == 120
every :: (a -> Int -> Bool) -> [a] -> BoolSource
Collection.every
is True
if f applies at all elements.
every (\i _ -> even i) [1,2,3,4] == False
occurencesOf :: Eq a => a -> [a] -> IntSource
zipWith_c :: (a -> b -> c) -> [a] -> [b] -> [c]Source
Variant of zipWith
that cycles the shorter input.
zipWith_c (+) [1,2] [3,4,5] == [4,6,6]
zipWith3_c :: (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d]Source
Variant of zipWith3
that cycles the shorter inputs.
zipWith3_c (,,) [1] [2,3] [4,5,6] == [(1,2,4),(1,3,5),(1,2,6)]
zip3_c :: [a] -> [b] -> [c] -> [(a, b, c)]Source
zipWith3_c
based variant of zip3
.
zip3_c [1] [2,3] [4,5,6] == [(1,2,4),(1,3,5),(1,2,6)]
zap_c :: [a -> b] -> [a] -> [b]Source
zipWith_c
based variant of applicative <*>
.
zap_c [(+1),negate] [1..6] == [2,-2,4,-4,6,-6]
Sequenceable Collection
series :: Num a => Int -> a -> a -> [a]Source
SequenceableCollection.*series
is an arithmetic series with
arguments size, start and step.
Array.series(5,10,2) == [10,12,14,16,18] series 5 10 2 == [10,12 .. 18]
Note that this is quite different from the SimpleNumber.series
method, which is equal to enumFromThenTo
.
5.series(7,10) == [5,7,9] enumFromThenTo 5 7 10 == [5,7,9]
geom :: Num a => Int -> a -> a -> [a]Source
SequenceableCollection.*geom
is a geometric series with arguments
size, start and grow.
Array.geom(5,3,6) == [3,18,108,648,3888] geom 5 3 6 == [3,18,108,648,3888]
fib :: Num a => Int -> a -> a -> [a]Source
SequenceableCollection.*fib
is the Fibonacci series where n
is number of elements, i is the initial step and j the initial
value.
Array.fib(5,2,32) == [32,34,66,100,166] fib 5 2 32 == [32,34,66,100,166]
SequenceableCollection.first
is a total variant of head
.
[3,4,5].first == 3 first [3,4,5] == Just 3 first' [3,4,5] == 3
[].first == nil first [] == Nothing
Total variant of last
.
(1..5).last == 5 lastM [1..5] == Just 5 L.last [1..5] == 5
[].last == nil lastM [] == Nothing
indexOf :: Eq a => [a] -> a -> Maybe IntSource
SequenceableCollection.indexOf
is a variant of elemIndex
with
reversed arguments.
[3,4,100,5].indexOf(100) == 2 indexOf [3,4,100,5] 100 == Just 2
indexOfEqual :: Eq a => [a] -> a -> Maybe IntSource
SequenceableCollection.indexOfEqual
is just indexOf
.
indexOfGreaterThan :: Ord a => a -> [a] -> Maybe IntSource
SequenceableCollection.indexOfGreaterThan
is the index of the
first greater element.
indexOfGreaterThan 70 [10,5,77,55,12,123] == Just 2
indexIn :: (Ord a, Num a) => a -> [a] -> IntSource
SequenceableCollection.indexIn
is the index of nearest element.
indexIn 5.2 [2,3,5,6] == 2
indexInBetween :: (Ord a, Fractional a) => a -> [a] -> aSource
SequenceableCollection.indexInBetween
is the linearly
interpolated fractional index.
indexInBetween 5.2 [2,3,5,6] == 2.2
keep :: Int -> [a] -> [a]Source
SequenceableCollection.keep
is, for positive n a synonym for
take
, and for negative n a variant on drop
based on the
length
of l.
[1,2,3,4,5].keep(3) == [1,2,3] keep 3 [1,2,3,4,5] == [1,2,3]
[1,2,3,4,5].keep(-3) == [3,4,5] keep (-3) [1,2,3,4,5] == [3,4,5]
[1,2].keep(-4) == [1,2] keep (-4) [1,2] == [1,2]
extension :: [[a]] -> [()]Source
Function to calculate a list equal in length to the longest input list, therefore being productive over infinite lists.
extension [[1],[2,3],[4,5,6]] == [(),(),()] take 3 (extension [[1],[2..]]) == [(),(),()]
SequenceableCollection.flop
is a variant of transpose
that
cycles input sequences and extends rather than truncates.
[(1..3),(4..5),(6..9)].flop == [[1,4,6],[2,5,7],[3,4,8],[1,5,9]] flop [[1..3],[4..5],[6..9]] == [[1,4,6],[2,5,7],[3,4,8],[1,5,9]]
[[1,2,3],[4,5,6],[7,8]].flop == [[1,4,7],[2,5,8],[3,6,7]] flop [[1,2,3],[4,5,6],[7,8]] == [[1,4,7],[2,5,8],[3,6,7]]
The null case at flop
is not handled equivalently to SC3
[].flop == [[]] flop [] /= [[]] flop [] == []
The flop
and extendSequences
functions are non-strict and
productive.
take 4 (flop [[1..3],[4..]]) == [[1,4],[2,5],[3,6],[1,7]] map (take 4) (extendSequences [[1..3],[4..]]) == [[1,2,3,1],[4,5,6,7]]
List and Array
lace :: Int -> [[a]] -> [a]Source
List.lace
is a concatenated transposition of cycled
subsequences.
[[1,2,3],[6],[8,9]].lace(12) == [1,6,8,2,6,9,3,6,8,1,6,9] lace 12 [[1,2,3],[6],[8,9]] == [1,6,8,2,6,9,3,6,8,1,6,9]
wrapExtend :: Int -> [a] -> [a]Source
List.wrapExtend
extends a sequence by
cycling. wrapExtend
is in terms of take
and cycle
.
[1,2,3,4,5].wrapExtend(9) == [1,2,3,4,5,1,2,3,4] wrapExtend 9 [1,2,3,4,5] == [1,2,3,4,5,1,2,3,4]
Infinite variant of foldExtend
.
foldExtend :: Int -> [a] -> [a]Source
List.foldExtend
extends sequence by folding backwards at end.
foldExtend
is in terms of cycleFold
, which is in terms of
mirror1
.
[1,2,3,4,5].foldExtend(10) foldExtend 10 [1,2,3,4,5] == [1,2,3,4,5,4,3,2,1,2]
clipExtend :: Int -> [a] -> [a]Source
Array.clipExtend
extends sequence by repeating last element.
[1,2,3,4,5].clipExtend(9) == [1,2,3,4,5,5,5,5,5] clipExtend 9 [1,2,3,4,5] == [1,2,3,4,5,5,5,5,5]
Infinite variant of clipExtend
.
extendSequences :: [[a]] -> [[a]]Source
Cycle input sequences to extension
of input.
separateAt :: (a -> a -> Bool) -> [a] -> ([a], [a])Source
Variant of separate
that performs initial separation.
separate :: (a -> a -> Bool) -> [a] -> [[a]]Source
SequenceableCollection.separate
applies the predicate f
to
each adjacent pair of elements at l. If the predicate is True
,
then a separation is made between the elements.
[3,2,1,2,3,2].separate({|a,b| a<b}) == [[3,2,1],[2],[3,2]] separate (<) [3,2,1,2,3,2] == [[3,2,1],[2],[3,2]]
[1,2,3,5,6,8].separate({|a,b| (b - a) > 1}) == [[1,2,3],[5,6],[8]] separate (\a b -> (b - a) > 1) [1,2,3,5,6,8] == [[1,2,3],[5,6],[8]]
clump :: Int -> [a] -> [[a]]Source
SequenceableCollection.clump
is a synonym for
splitEvery
.
[1,2,3,4,5,6,7,8].clump(3) == [[1,2,3],[4,5,6],[7,8]] clump 3 [1,2,3,4,5,6,7,8] == [[1,2,3],[4,5,6],[7,8]]
clumps :: [Int] -> [a] -> [[a]]Source
SequenceableCollection.clumps
is a synonym for
splitPlaces
.
[1,2,3,4,5,6,7,8].clumps([1,2]) == [[1],[2,3],[4],[5,6],[7],[8]] clumps [1,2] [1,2,3,4,5,6,7,8] == [[1],[2,3],[4],[5,6],[7],[8]]
integrate :: Num a => [a] -> [a]Source
SequenceableCollection.integrate
is the incremental sum of
elements.
integrate [3,4,1,1] == [3,7,8,9]
differentiate :: Num a => [a] -> [a]Source
SequenceableCollection.differentiate
is the pairwise difference
between elements.
differentiate [3,4,1,1] == [3,1,-3,0]
rotateLeft :: Int -> [a] -> [a]Source
Rotate n places to the left.
rotateLeft 3 [1..7] == [4,5,6,7,1,2,3]
rotateRight :: Int -> [a] -> [a]Source
Rotate n places to the right.
rotateRight 3 [1..7] == [5,6,7,1,2,3,4]
normalizeSum :: Fractional a => [a] -> [a]Source
ArrayedCollection.normalizeSum
ensures sum of elements is one.
normalizeSum [1,2,3] == [1/6,2/6,3/6]
slide :: Int -> Int -> [a] -> [a]Source
List.slide
is an identity window function with subsequences of
length w and stride of n.
[1,2,3,4,5,6].slide(3,1) slide 3 1 [1,2,3,4,5,6] == [1,2,3,2,3,4,3,4,5,4,5,6]
[1,2,3,4,5,6].slide(3,2) slide 3 2 [1,2,3,4,5,6] == [1,2,3,3,4,5]
[1,2,3,4,5,6].slide(4,2) slide 4 2 [1,2,3,4,5,6] == [1,2,3,4,3,4,5,6]
List.mirror1
is as mirror
but with last element removed.
[1,2,3,4].mirror1 == [1,2,3,4,3,2] mirror1 [1,2,3,4] == [1,2,3,4,3,2]
stutter :: Int -> [a] -> [a]Source
List.stutter
repeats each element n times.
[1,2,3].stutter(2) == [1,1,2,2,3,3] stutter 2 [1,2,3] == [1,1,2,2,3,3]
rotate :: Int -> [a] -> [a]Source
Array.rotate
is in terms of rotateLeft
and rotateRight
,
where negative n rotates left and positive n rotates right.
(1..5).rotate(1) == [5,1,2,3,4] rotate 1 [1..5] == [5,1,2,3,4]
(1..5).rotate(-1) == [2,3,4,5,1] rotate (-1) [1..5] == [2,3,4,5,1]
(1..5).rotate(3) == [3,4,5,1,2] rotate 3 [1..5] == [3,4,5,1,2]