A set of threading macros blatantly rewritten from cl-arrows.
- [X] Formalise direction
- [ ] Find more arrow ideas (this is now a small obsession)
- [ ] Implement parts from srfi 197
- [ ] Implement arrows from the racket threading library
- [ ] Implement arrows from the swiss arrows library
- [X] Add an inspect function similar to elixirs for easier debugging
- [X] nil short circuiting arrows, these will return nil if any of the forms return nil.
- Roadmap
- Reference
- Macros
- =arr->= (initial-forms &rest forms)
- =arr->>= (initial-form &rest forms)
- =arr-<>= (initial-form &rest forms)
- =arr-<>>= (initial-form &rest forms)
- =arr-?>= (initial-form &rest forms)
- =arr-?>>= (initial-form &rest forms)
- =arr-<?>= (initial-form &rest forms)
- =arr-<?>>= (initial-form &rest forms)
- =arr->*= (&rest forms)
- =arr-as->= (initial-form name &rest forms)
- =arr-as->*= (name &rest forms)
- Functions
- Macros
- Examples
Inserts the INITIAL-FORM as the first argument into FORMS
The result of each form is inserted as first of the next form.
Identical to thread-first
Fn variant: arr-fn->
(arr-> 8 1+ number-to-string (string-pad 5) (string-pad 9 nil t))
9
Inserts the INITIAL-FORM as the last argument into forms
The result of each form is then inserted as the last into the next form
Identical to thread-last
Fn variant: arr-fn->>
(arr->> '(1 2 3 4 5)
(seq-map #'1+)
(seq-filter #'cl-evenp))
2 | 4 | 6 |
Inserts the INITIAL-FORM as the first argument into FORMS unless there is a
placeholder <>
This is used for functions that do not have uniform argument placement. a
placement can be used many time in the same form, they will only be executed
once. Placeholders can’t be nested.
Fn variant: arr-fn-<>
EXAMPLE TODO
Inserts the INITIAL-FORM as the last argument into FORMS unless there is a
placeholder <>
This is used for functions that do not have a uniform argument placement. a
placement can be used many times in the same form, they will only be executed
once. Placeholders can’t be nested.
Fn variant: arr-fn-<>>
(arr-<>> '(1 2 3 4 5)
(seq-map #'1+)
(seq-filter #'cl-evenp)
(seq-reduce #'+ <> 0))
12
Insert the INITIAL-FORM as the first argument into FORMS The result of each form is inserted as the first of the next forms. If a form evaluates to nil, the pipeline stops executing and returns nil
useful when you have a form that can fail and don’t want to catch a type error.
Fn variant: arr-fn-?>
EXAMPLE TODO
Insert the INITIAL-FORM as the last argument into FORMS The result of each form is inserted as the last of the next forms. If a form evaluates to nil, the pipeline stops executing and returns nil
useful when you have a form that can fail and don’t want to catch a type error.
Fn variant: arr-fn-?>>
EXAMPLE TODO
Inserts the INITIAL-FORM as the first argument into FORMS unless there is a
placeholder <>
This is used for functions that do not have uniform argument placement. a
placement can be used many time in the same form, they will only be executed
once. Placeholders can’t be nested.
useful when you have a form that can fail and don’t want to catch a type error.
Fn variant: arr-fn-<?>
EXAMPLE TODO
Inserts the INITIAL-FORM as the last argument into FORMS unless there is a
placeholder <>
This is used for functions that do not have uniform argument placement. a
placement can be used many time in the same form, they will only be executed
once. Placeholders can’t be nested.
useful when you have a form that can fail and don’t want to catch a type error.
Fn variant: arr-fn-<?>>
EXAMPLE TODO
Inserts the last form in FORMS through FORMS as the first argument. This is used in composition with arr->> or any other macro that threads there arguments last.
Fn variant: nil
EXAMPLE TODO
Inserts the INITIAL-FORM as NAME through FORMS. each form requires that name be present. there is no implicit threading unlike the other macro’s
Syntactic sugar for the pattern of redefining a var through a recursive let.
EXAMPLE TODO
Inserts the last form in FORMS through FORMS as NAME. This is like arr->* and arr-as-> with the last form being passed in as the inital, being passed through as NAME. use this in composition with arr->> or any other macro that threads there argument last
a way to quickly print out the value in a pipeline without disrupting it. Used for debugging. Provide a PRINT-FN which takes in a VALUE and LABEL to use your own interface. return value is discarded.
EXAMPLE TODO
We also provide composition functions which are useful when you want to have a
function that represents a set of transformations. this also allows your code to
look point free. All arrow macro’s have a fn
variant.
(require 'arr)
(seq-map (arr-fn-> (1+) (number-to-string)) '(1 2 3))
2 | 3 | 4 |
As a side effect this allows for short functions without the need for the full lambda syntax. This is not as nice nor as flexible as something like dollar.el but still is worth mentioning.
(seq-map (arr-fn-<> (* <> <>)) '(2 3 4))
4 | 9 | 16 |