6 Utilities for Lists and Natural Numbers
(require lathe-comforts/list) | |
package: lathe-comforts-lib |
6.1 Utilities for Natural Numbers
procedure
(nat->maybe n) → (maybe/c natural?)
n : natural?
6.2 Utilities for Lists
procedure
(list-foldl state lst func) → any/c
state : any/c lst : list? func : (-> any/c any/c any/c)
The function func is passed two values: The current state value and the list element to process. Its return value is used as the updated state value.
Racket already provides a foldl function, but this one arranges the function to be the last argument.
procedure
(list-foldr lst state func) → any/c
lst : list? state : any/c func : (-> any/c any/c any/c)
The function func is passed two values: The list element to process and the current state value. Its return value is used as the updated state value.
Racket already provides a foldr function, but this one arranges the function to be the last argument, and it switches the order of the list and initial state arguments so the initial state is visually closer to the side of the list it interacts with.
The elements are processed from first to last.
Racket already provides an append-map function, but this one arranges the function to be the last argument.
The elements are processed from first to last.
Racket already provides a map function, but this one arranges the function to be the last argument.
If the list is empty, the overall result is #f. Otherwise, if the function does return a non-#f value for any but the last element, then that value is used as the overall result. Otherwise, the (possibly multiple) return values of calling the function with the last element are used as the result.
Racket already provides an ormap function, but this one arranges the function to be the last argument.
If the list is empty, the overall result is #t. Otherwise, if the function does return #f for any but the last element, then the overall result is #f. Otherwise, the (possibly multiple) return values of calling the function with the last element are used as the result.
Racket already provides an andmap function, but this one arranges the function to be the last argument.
Racket already provides a for-each function, but this one arranges the function to be the last argument.
If the list is empty, the overall result is #f. Otherwise, if the function does return a non-#f value for any but the last entry, then that value is used as the overall result. Otherwise, the (possibly multiple) return values of calling the function with the last entry’s index and value are used as the result.
If the list is empty, the overall result is #t. Otherwise, if the function does return #f for any but the last entry, then the overall result is #f. Otherwise, the (possibly multiple) return values of calling the function with the last entry’s index and value are used as the result.
The elements are processed from first to last.
Racket already provides a map function, but this one arranges the function to be the last argument.
If the lists are empty, the overall result is #f. Otherwise, if the function does return a non-#f value for any but the last pair of elements, then that value is used as the overall result. Otherwise, the (possibly multiple) return values of calling the function with the last pair of elements are used as the result.
Racket already provides an ormap function, but this one arranges the function to be the last argument.
If the lists are empty, the overall result is #t. Otherwise, if the function does return #f for any but the last pair of elements, then the overall result is #f. Otherwise, the (possibly multiple) return values of calling the function with the last pair of elements are used as the result.
Racket already provides an andmap function, but this one arranges the function to be the last argument.
Racket already provides a for-each function, but this one arranges the function to be the last argument.
6.3 Utilities for Natural Numbers and Lists Together
procedure
(list-length<=nat? lst n) → boolean?
lst : list? n : natural? (nat<=list-length? n lst) → boolean? n : natural? lst : list? (list-length=nat? lst n) → boolean? lst : list? n : natural? (list-length<nat? lst n) → boolean? lst : list? n : natural? (nat<list-length? n lst) → boolean? n : natural? lst : list?