Skip to content

A set of threading macro's for our favorite operating system

License

Notifications You must be signed in to change notification settings

jeetelongname/el-arrows

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Arrows

A set of threading macros blatantly rewritten from cl-arrows.

Roadmap

Arrows to implement

  • [X] nil short circuiting arrows, these will return nil if any of the forms return nil.

Table of Contents

Reference

Macros

arr-> (initial-forms &rest forms)

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

arr->> (initial-form &rest forms)

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))
246

arr-<> (initial-form &rest forms)

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

arr-<>> (initial-form &rest forms)

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

arr-?> (initial-form &rest forms)

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

arr-?>> (initial-form &rest forms)

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

arr-<?> (initial-form &rest forms)

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

arr-<?>> (initial-form &rest forms)

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

arr->* (&rest forms)

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

arr-as-> (initial-form name &rest forms)

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

arr-as->* (name &rest forms)

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

Functions

arr-inspect (value &optional &key print-fn label)

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

Examples

fn Example

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))
234

Lambda Short-hands

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))
4916

About

A set of threading macro's for our favorite operating system

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published