Index
Strasheela
Init
GUtils
LUtils
MUtils
Score
SMapping
SDistro
Out
Strasheela
FD_edited
Midi
This functor defines some general list utilities

Functor

Import

Export

Define

fun{Mappend Xs Fn}
Map function Fn (which must return a list) over all elements of list Xs and append all resulting lists.


fun{CollectN N Fn}
Return a list of N elements, each element is bound to the result of calling the unary procedure Fn.


fun{RepeatN N X}
Return a list of N elements, each element is bound to the same X.


fun{Contains X Ys}
Returns true if Ys contains X and false otherwise.


fun{Position X Ys}
Returns position of the first occurence of X in list Ys.


fun{Positions X Ys}
Returns the positions of all occurences of X in list Ys.


fun{FindPosition Xs Fn}
Returns position of the first element in X for which Fn returns true.


fun{FindPositions Xs Fn}
Returns position of all elements in X for which Fn returns true.


fun{RemovePosition Xs Pos}
Remove the element of Xs at position Pos.


fun{ReplacePosition Xs Pos Y}
Replace the element of Xs at position Pos by Y.


fun{RemoveDuplicates Xs}
Removes any element in Xs (a list of arbitrary data) which occured already more early in X. Elements are compared with ==.


fun{Remove Xs Fn}
Remove returns a list of the elements in Xs for which the application of the unary boolean function Fn yields false. In the output, the ordering in Xs is preserved.


fun{Find Xs Fn}
Find returns the first element in Xs for which the application of the unary boolean function Fn yields true.


fun{FindBest Xs Fn}
Returns the (first) member of Xs that performs best according to the binary Boolean function (comparison function) Fn.
FindBest is something like sort that only returns the best match.


proc{CFilter Xs F Result}
Concurrent variant of Filter. Like Filter, CFilter returns a stream/list of elements in Xs for which F (a Boolean function) returns true. However, CFilter does not necessarily completely block on free variables in Xs. Instead, it returns/skips elements of Xs as soon as enough information is provided to decided either way, possibly changing the order of list elements. If it is known that no elements will be added, then the stream Result will be closed.
Less efficient than Filter (e.g., many threads are created).


proc{CFind Xs F Result}
Concurrent variant of Find. Like Find, CFind returns one element in Xs for which F returns true. However, the Result is not necessarily the first 'matching' element in Xs. CFind returns a result as soon as enough information is available to decide for any element -- even if free variables are in Xs before that element.
Less efficient than Find (e.g., many threads are created).


fun{Substitute Xs Old New}
Replaces all occurances of Old in Xs by New.


fun{Substitute1 Xs Old New}
Replaces the first occurance of Old in Xs by New.


fun{Count Xs Fn}
Returns the number of elements in Xs for which the unary boolean function Fn returns true.


proc{Accum Xs Fn Y}
Binds the accumulation of the binary function Fn on all neighbors in Xs to Y. E.g., Accum returns the sum in Xs if Fn is Number.'+'.


fun{SubtractList Xs Ys}
SubtractList returns a list which contains all elements of Xs except the (leftmost occurrences of) elements in Ys if they are in Xs.


fun{Split Xs Y}
Splits Xs at all occurences of Y. Split returns a list of sublists between (possibly multiple) Y and skips Y itself.
NB: String.tokens does the same..
NB: if last element of list is Y, then it is simply omitted.


fun{Sublist Xs Start End}
Returns the sublist of Xs that consists in the Start-th to End-th elements (including). If End > {Length Xs}, sublist returns a sublist up to the last element of Xs.


fun{Sublists Xs Decls}
Returns the list of sublists of Xs (a list) such that each sublist is declared by a range in Decls. Decls is a list consisting in integers and/or pairs of the form Start#End (two integers).


fun{MatTrans Xss}
Quasi a matrix transformations: transforms a list of form [[a1 a2 ... an] [b1 b2 ... bn] ... [n1 n2 ... nn]] into [[a1 b1 ... n1] [a2 b2 ... n2] ... [an bn ... nn]].


fun{NthWrapped Xs N}
Returns element of Xs at index N. However, if N is outside the interval [1, {Length Xs}] NthWrapped 'wraps' N back into this interval. I.e. if N={Length Xs}+1 NthWrapped returns Xs.1

fun{EveryNth Xs N Offset}
Returns a list with every N-th element of Xs (by preserving the order). Offset specifies an offset for the element to start (if Offset=0 the first element of Xs is the first element of the result).
NB: causes infinite loop if N=0.


fun{OddPositions Xs}
Returns a list with every N-th element of Xs (by preserving the order).
NB: causes infinite loop if N=0.
*/
fun {EveryNth Xs N}
transform into tuple to allow for constant time access (is this really more efficient?)
XR = {List.toTuple unit Xs}
in
for I in 1..{Width XR};N
collect:C
do {C XR.I}
end
end

/** %% Returns every element in Xs at an odd position.


fun{EvenPositions Xs}
Returns every element in Xs at an even position.


fun{Replace Xs R}
Replaces all elements in Xs (a list of atoms) by the value in the record R at the feature equal to the list element. If R has no such feature the list element remains.


fun{ButLast Xs}
Returns all but the last elements of Xs


fun{LastN Xs N}
Returns the last N elements of Xs (quasi the opposite of List.take).


fun{ArithmeticSeries Start Difference N}
Returns an arithmetic series with N elements, starting from start and with difference Difference between the elements.
Start and Difference must be floats, N must be an integer. A list of floats is returned.


fun{ReciprocalArithmeticSeries Start Difference N}
Returns the reciprocals of an arithmetic series with N elements. The arithmetic series starts from start and has difference Difference between its elements. Start and Difference must be floats, N must be an integer. A list of floats is returned.
The reciprocal series is not transposed, i.e. for Difference>0 seach series element is smaller than its predecessor and all but the first series elements are < Start.


[class info]

An ExtendableList instance provides the feature list, which is a list whose tail is unbound. The list is a stateless data structure. However, new list elements can be added at the tail of the list.
This datastructure is similar to a Port. The difference is that (i) the tail is not protected (no read-only variable) and (ii) the resulting stream can be closed, thus transforming the stream into a proper list.
NB: adding new list elements is a stateful operation (the binding of the internal attribute tail is changed), but the state is completely encapsulated in this data structure.

class ExtendableList
   feat list !ExtendableListType end

fun{IsExtendableList X}
Returns a boolean whether X is an ExtendableList


End