On this page:
datum-fold
default-fold-short-circuit
default-fold-list
default-fold-list*
default-fold-vector
default-fold-box
default-fold-prefab
default-fold-hash
default-fold-syntax
default-fold-other
7.1

7.6 mischief/fold: Folding Over Common Datatypes

 (require mischief/fold) package: mischief

procedure

(datum-fold x    
  [#:short-circuit fold-short-circuit    
  #:list fold-list    
  #:list* fold-list*    
  #:vector fold-vector    
  #:box fold-box    
  #:prefab fold-prefab    
  #:hash fold-hash    
  #:hash-eq fold-hash-eq    
  #:hash-eqv fold-hash-eqv    
  #:hash-equal fold-hash-equal    
  #:syntax fold-syntax    
  #:other fold-other])  any/c
  x : any/c
  fold-short-circuit : (-> any/c (-> any/c) any/c)
   = default-fold-short-circuit
  fold-list : (-> list? any/c) = default-fold-list
  fold-list* : (-> list? (not/c list?) any/c)
   = default-fold-list*
  fold-vector : (-> list? any/c) = default-fold-vector
  fold-box : (-> any/c any/c) = default-fold-box
  fold-prefab : (-> prefab-key? list? any/c)
   = default-fold-prefab
  fold-hash : (-> hash? list? list? any/c) = default-fold-hash
  fold-hash-eq : (-> list? list? any/c)
   = (arg+ default-fold-hash (hasheq))
  fold-hash-eqv : (-> list? list? any/c)
   = (arg+ default-fold-hash (hasheqv))
  fold-hash-equal : (-> list? list? any/c)
   = (arg+ default-fold-hash (hash))
  fold-syntax : (-> syntax? any/c any/c) = default-fold-syntax
  fold-other : (-> (-> any/c any/c) any/c any/c)
   = default-fold-other
Constructs a result by folding over x. At each recursive step, first calls fold-short-circuit with the current input value and a thunk that computes the result for that value. If that thunk is called, continues using fold-list, fold-list*, fold-vector, fold-box, fold-prefab, fold-hash-eq, fold-hash-eqv, fold-hash-equal, fold-syntax, and fold-other as appropriate. All of the above functions except fold-other are called with the result of recurring on their sub-parts; fold-other is called with a recursive folding procedure and the current input value.

procedure

(default-fold-short-circuit x proc)  any/c

  x : any/c
  proc : (-> any/c)

procedure

(default-fold-list xs)  any/c

  xs : list?

procedure

(default-fold-list* head tail)  any/c

  head : list?
  tail : (not/c list?)

procedure

(default-fold-vector xs)  any/c

  xs : list?

procedure

(default-fold-box x)  any/c

  x : any/c

procedure

(default-fold-prefab key fields)  any/c

  key : prefab-key?
  fields : list?

procedure

(default-fold-hash table keys vals)  any/c

  table : hash?
  keys : list?
  vals : list?

procedure

(default-fold-syntax stx x)  any/c

  stx : syntax?
  x : any/c

procedure

(default-fold-other proc x)  any/c

  proc : (-> any/c any/c)
  x : any/c
Default folding functions. The default-fold-short-circuit function simply calls the provided thunk; default-fold-other returns its second argument. The other functions reconstitute their arguments into the corresponding data type (list, improper list, etc.).