Version0.9.3Verifiednot yet verifiedLicenseBSD-3-Clause

sigil-fp

Functional programming utilities for Sigil

Report a bug or suggest a feature
Readme

sigil-fp

Archived at Sigil 0.19.0: The maintained implementation now lives in codeberg:sigil/sigil. This repository and all tags remain available for provenance, but no further standalone releases will be published.

Functional programming utilities for Sigil, providing function composition, partial application, and threading macros.

Installation

Add to your package.sgl dependencies:

(from-git url: "codeberg:sigil/sigil-fp")

Modules

(sigil fp fn) - Function Composition

Utilities for composing and partially applying functions.

(import (sigil fp fn))

partial / partial-right

Create new functions by fixing arguments:

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

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

compose

Right-to-left function composition:

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

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

pipe

Left-to-right function composition (pipeline style):

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

const

Read the rest

Return a function that always returns the given value:

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

flip

Swap the first two arguments of a function:

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

complement

Return the logical complement of a predicate:

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

juxt

Apply multiple functions to the same arguments, returning a list of results:

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

(sigil fp chain) - Threading Macros

Thread values through sequences of expressions, similar to Clojure's threading macros and SRFI-197.

These macros live in (sigil core) now. chain, ->, and some-> are part of core, which is auto-imported into every module, so every program already has them in scope without importing anything. (sigil fp chain) re-exports them from core purely for backward compatibility, so existing (import (sigil fp chain)) / (import (sigil fp)) code keeps working.
;; No import needed — these come from core:
(-> 5 (+ 3) (* 2))

;; Or, for backward compatibility:
(import (sigil fp chain))

chain / ->

Thread a value through expressions. Uses _ as a placeholder for the threaded value. When no _ is present, the value is inserted as the first argument.

;; Thread-first (no placeholder)
(chain 5 (+ 3) (* 2))
; => 16

;; Explicit placeholder
(chain '(1 2 3)
       (map (lambda (x) (* x 2)) _)
       (apply + _))
; => 12

;; Placeholder in various positions
(chain 10 (- 20 _))          ; => 10
(chain 5 (list 1 2 _ 4))     ; => (1 2 5 4)

;; -> is an alias for chain
(-> 5 (+ 3) (* 2))  ; => 16

some->

Like ->, but short-circuits and returns #f if any step produces #f:

;; Short-circuits on #f
(some-> #f (+ 1 _))  ; => #f

;; Continues while truthy
(some-> 5 (+ 1 _) (* 2 _))  ; => 12

;; Useful for nullable pipelines
(some-> user
        (dict-ref _ name:)
        (string-split " " _)
        car)

Building

sigil deps install
sigil build
sigil test

License

BSD-3-Clause

Clone

$ git clone https://codeberg.org/sigil/sigil-fp

Releases

v0.9.3 — latest by version, released 6 Jul 2026

All releases — 3 tags in this repository.

Source

Browse the latest source

One page per file, and every line has a permalink.

Recent commitsAtom

The last 20 commits keep a page here. Everything older lives in the clone.