Skip to content

Commit

Permalink
Propose project with the functionality of projection ...
Browse files Browse the repository at this point in the history
... but an API similar to `invert`.
  • Loading branch information
markusschlegel committed Jun 10, 2024
1 parent 34ce0a5 commit 82348ab
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/active/clojure/lens.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,21 @@ right-most element where they were before."} merge
(lens (f/partial projection-yank empty fields)
(f/partial projection-shove fields))))

(defn project
"A lens that projects multiple derived values into a new value,
with an optional `empty` being an initial new value, and `fields` a map or
sequence of tuples, of a lens on the new value and lens over the
'outer' value the lens is used on.
Example:
```
(projection {(at-index 0) :a
(at-index 1) :b})
```
"
[fields & [empty]]
(projection empty fields))

(let [invert-yank (fn invert-yank [l empty data]
(shove empty l data))
invert-shove (fn invert-shove [l _data v]
Expand Down

0 comments on commit 82348ab

Please sign in to comment.