2021-02-05

(sph list other)

additional list processing bindings that depend on libraries that depend on (sph list). to avoid circular dependencies

part of sph-lib

module name

(sph list other)

exported bindings

procedure: group a [accessor] ->
list [procedure:{any -> any}] -> ((any:group-key any:group-value ...):group ...)
groups entries by unique result values of accessor.
by default accessor is identity and groups equal elements.
returns an association list with one entry for each group with the value as key and related values as value
procedure: group-recursively a [accessor] ->
((any ...) ...) [procedure] -> list
group lists and the elements of groups until no further sub-groups are possible.
the default accessor is \"first\".
# example
(group-recursively (list (list 1 2 3) (list 1 2 6) (list 1 4 7) (list 8 9)) first)
-> ((1 (2 3 6) (4 7)) (8 9))
note in the example input how the entries after 1 2 have been grouped into (2 3 6)
# example use case
converting a list of filesystem paths split at slashes to a nested list where prefixes are directories
procedure: list-ref-random a [random-state] ->
list -> any
retrieve a random element of a list
procedure: list-ref-randomise-cycle a [random-state] ->
list -> procedure:{ -> any}
gives a procedure that when called gives the next element from a randomised version of \"a\"
when the end of the list has been reached, the list is reset to a newly randomised version of \"a\"
procedure: list-replace-from-hashtable a ht ->
list rnrs-hashtable -> list
replaces elements in list that exist as key in a hashtable with the associated value.
if the value is a list, the element is either removed (empty list) or replaced with multiple elements
procedure: randomise a [random-state] ->
list -> list
return a new list with the elements of list in random order.
algorithm: connect a random number to each element, re-sort list corresponding to the random numbers.
variable: sph-list-other-description