sigildocs

(sigil fn)

Exports

partialprocedure

Create a new function with some arguments pre-filled from the left.

The returned function accepts additional arguments which are appended to the fixed arguments when calling the original procedure.

(define add10 (partial + 10))
(add10 5)      ; => 15
(add10 1 2 3)  ; => 16

(define greet (partial string-append "Hello, "))
(greet "World!")  ; => "Hello, World!"
partial-rightprocedure

Create a new function with some arguments pre-filled from the right.

The returned function accepts additional arguments which are prepended to the fixed arguments when calling the original procedure.

(define subtract-from-10 (partial-right - 10))
(subtract-from-10 3)  ; => -7 (= 3 - 10)

(define div-by-2 (partial-right / 2))
(div-by-2 10)  ; => 5 (= 10 / 2)
composeprocedure

Compose functions right-to-left.

Returns a function that applies the rightmost function first, then passes its result to the next function, and so on. With no arguments, returns identity.

((compose f g h) x)  ; => (f (g (h x)))

(define process (compose string-upcase string-trim))
(process "  hello  ")  ; => "HELLO"

((compose) 42)  ; => 42 (identity)
pipeprocedure

Compose functions left-to-right (pipeline style).

Returns a function that applies the leftmost function first, then passes its result to the next function, and so on. This is the opposite of compose and often more intuitive for data pipelines.

((pipe f g h) x)  ; => (h (g (f x)))

(define process (pipe string-trim string-upcase))
(process "  hello  ")  ; => "HELLO"
constprocedure

Return a function that always returns the given value.

Useful for providing constant values to higher-order functions.

(map (const 0) '(a b c))  ; => (0 0 0)

(define always-true (const #t))
(always-true 'anything)  ; => #t
flipprocedure

Return a function with its first two arguments swapped.

((flip cons) '(1 2) 'a)  ; => (a 1 2)
((flip -) 3 10)          ; => 7 (= 10 - 3)
((flip /) 2 10)          ; => 5 (= 10 / 2)
complementprocedure

Return the logical complement of a predicate.

(define not-empty? (complement null?))
(not-empty? '(1 2 3))  ; => #t
(not-empty? '())       ; => #f

(filter (complement zero?) '(0 1 0 2 0 3))  ; => (1 2 3)
juxtprocedure

Return a function that applies multiple functions to the same arguments.

Returns a list of results, one from each function.

((juxt car cdr) '(1 2 3))  ; => (1 (2 3))
((juxt + - *) 3 4)         ; => (7 -1 12)

(map (juxt string-upcase string-length) '("hi" "hello"))
; => (("HI" 2) ("HELLO" 5))