AtlatestRepositorysigil-fp
1
# sigil-fp3
> **Archived at Sigil 0.19.0:** The maintained implementation now lives in4
> `codeberg:sigil/sigil`. This repository and all tags remain available for5
> provenance, but no further standalone releases will be published.7
Functional programming utilities for [Sigil](https://codeberg.org/sigil/sigil), providing function composition, partial application, and threading macros.9
## Installation11
Add to your `package.sgl` dependencies:13
```scheme14
(from-git url: "codeberg:sigil/sigil-fp")15
```17
## Modules19
### (sigil fp fn) - Function Composition21
Utilities for composing and partially applying functions.23
```scheme24
(import (sigil fp fn))25
```27
#### partial / partial-right29
Create new functions by fixing arguments:31
```scheme32
(define add10 (partial + 10))33
(add10 5) ; => 1534
(add10 1 2 3) ; => 1636
(define div-by-2 (partial-right / 2))37
(div-by-2 10) ; => 538
```40
#### compose42
Right-to-left function composition:44
```scheme45
(define process (compose string-upcase string-trim))46
(process " hello ") ; => "HELLO"48
((compose) 42) ; => 42 (identity)49
```51
#### pipe53
Left-to-right function composition (pipeline style):55
```scheme56
(define process (pipe string-trim string-upcase))57
(process " hello ") ; => "HELLO"58
```60
#### const62
Return a function that always returns the given value:64
```scheme65
(map (const 0) '(a b c)) ; => (0 0 0)66
```68
#### flip70
Swap the first two arguments of a function:72
```scheme73
((flip cons) '(1 2) 'a) ; => (a 1 2)74
((flip -) 3 10) ; => 775
```77
#### complement79
Return the logical complement of a predicate:81
```scheme82
(filter (complement zero?) '(0 1 0 2 0 3)) ; => (1 2 3)83
```85
#### juxt87
Apply multiple functions to the same arguments, returning a list of results:89
```scheme90
((juxt car cdr) '(1 2 3)) ; => (1 (2 3))91
((juxt + - *) 3 4) ; => (7 -1 12)92
```94
### (sigil fp chain) - Threading Macros96
Thread values through sequences of expressions, similar to Clojure's threading macros and SRFI-197.98
> **These macros live in `(sigil core)` now.** `chain`, `->`, and `some->` are99
> part of core, which is auto-imported into every module, so every program100
> already has them in scope without importing anything. `(sigil fp chain)`101
> re-exports them from core purely for backward compatibility, so existing102
> `(import (sigil fp chain))` / `(import (sigil fp))` code keeps working.104
```scheme105
;; No import needed — these come from core:106
(-> 5 (+ 3) (* 2))108
;; Or, for backward compatibility:109
(import (sigil fp chain))110
```112
#### chain / ->114
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.116
```scheme117
;; Thread-first (no placeholder)118
(chain 5 (+ 3) (* 2))119
; => 16121
;; Explicit placeholder122
(chain '(1 2 3)123
(map (lambda (x) (* x 2)) _)124
(apply + _))125
; => 12127
;; Placeholder in various positions128
(chain 10 (- 20 _)) ; => 10129
(chain 5 (list 1 2 _ 4)) ; => (1 2 5 4)131
;; -> is an alias for chain132
(-> 5 (+ 3) (* 2)) ; => 16133
```135
#### some->137
Like `->`, but short-circuits and returns `#f` if any step produces `#f`:139
```scheme140
;; Short-circuits on #f141
(some-> #f (+ 1 _)) ; => #f143
;; Continues while truthy144
(some-> 5 (+ 1 _) (* 2 _)) ; => 12146
;; Useful for nullable pipelines147
(some-> user148
(dict-ref _ name:)149
(string-split " " _)150
car)151
```153
## Building155
```156
sigil deps install157
sigil build158
sigil test159
```161
## License163
BSD-3-Clause