List utilities
1 API
findf-index
group-by
all-splits-on
subsequences
replace-sublist
frequencies
enumerate
splice-in
7.7

List utilities

Vincent Nys

This is a simple collection of list-processing functions which I have found helpful in general. Note that it should not be considered as stable.

1 API

procedure

(findf-index proc lst)  (or/c #f exact-nonnegative-integer?)

  proc : (-> any/c boolean?)
  lst : list?
Finds the index of the first element in lst such that proc returns a non-false result.

procedure

(group-by proc lst)  list?

  proc : (-> any/c any/c)
  lst : list?
Splits a list lst into sublists such that all elements in a sublist have the same result for proc (based on equal?).

procedure

(all-splits-on pred lst)  (listof list?)

  pred : (-> any/c boolean?)
  lst : list?
Computes all possible splits of lst on a supplied predicate pred.

procedure

(subsequences lst)  (listof list?)

  lst : list?
Returns a list of all nonempty subsequences of lst.

procedure

(replace-sublist lst sublst/i sublst/o)  list?

  lst : list?
  sublst/i : list?
  sublst/o : list?
Replaces the first occurrence of the sublist sublst/i in lst with sublst/o.

procedure

(frequencies lst)  hash?

  lst : list?
Produces a mapping from every unique element in lst to its (absolute) frequency in lst.

procedure

(enumerate lst)

  (listof (cons/c any/c exact-nonnegative-integer?))
  lst : (listof any/c)
Links the n-th element in lst to index n, where n starts at 0.

procedure

(splice-in lst val pos)  list?

  lst : list?
  val : any/c
  pos : exact-nonnegative-integer?
Inserts val at position pos of lst, shifting the element that originally occupied pos (if any) one position to the right.