Harpoons
Harpoons is a Clojure and Clojurescript library providing a set of new threading macros that complement and compose well with the existing core threading macros.
Starting threading context
Start a normal threading context:
(->
…
)
(->>
…
)
(-<>
…
)
Start a short-circuiting threading context that exits at the first nil value:
(some->
…
)
(some->>
…
)
(some-<>
…
)
Start a short-circuiting threading context that exits at the first non-nil value:
(non-nil->
…
)
(non-nil->>
…
)
(non-nil-<>
…
)
Start a conditional threading context:
(cond->
…
)
(cond->>
…
)
(cond-<>
…
)
Modifying threading context
Convert the enclosing threading context into a corresponding short-circuiting context that exits at the first nil value:
(>-some
…
)
(>>-some
…
)
(<>-some
…
)
Convert the enclosing threading context into a corresponding short-circuiting context that exits at the first non-nil value:
(>-non-nil
…
)
(>>-non-nil
…
)
(<>-non-nil
…
)
Convert the enclosing threading context into a corresponding conditional threading context:
(>-cond
…
)
(>>-cond
…
)
(<>-cond
…
)
Bind the threaded value to the symbols in
destructuring the value as necessary:(>-bind
…
)
(>>-bind
…
)
(<>-bind
…
)
Evaluating body within threading context
Bind the threaded value to the symbols in
destructuring the value as necessary. Evaluate the body forms returning the value of the last form back to the enclosing threading context:(>-let
…
)
(>>-let
…
)
(<>-let
…
)
Evaluate the body forms returning the value of the last form back to
the enclosing threading context. The threaded value is bount to the <>
symbol throughout the scope of the body:
(>-do
…
)
(>>-do
…
)
(<>-do
…
)
Evaluate the body forms for the side-effects only without altering the
threaded value in the enclosing threading context. The threaded value
is bound to the <>
symbol throughout the scope of the body:
(>-fx!
…
)
(>>-fx!
…
)
(<>-fx!
…
)
Bridging between different threading contexts
Bridge to an inner >
threading context. Note that when bridging from an outer <>
context the value threaded in the context remain bound to the <>
symbol and, thus, is accessible throughout the scope of the bridging
form:
(>>->
…
)
(<>->
…
)
Bridge to an inner >>
threading context. Note that when bridging from an outer <>
context the value threaded in the context remain bound to the <>
symbol and, thus, is accessible throughout the scope of the bridging
form:
(>->>
…
)
(<>->>
…
)
Bridge to an inner <>
threading context.
(>-<>
…
)
(>>-<>
…
)