Skip to content

Instantly share code, notes, and snippets.

@jaawerth
Created May 10, 2019 03:39
Show Gist options
  • Save jaawerth/42e84e30e9f87715e3d728774541b952 to your computer and use it in GitHub Desktop.
Save jaawerth/42e84e30e9f87715e3d728774541b952 to your computer and use it in GitHub Desktop.
(macros
{:list-map
(fn list-map [mapper tgt]
(when (not (list? tgt)) (error (.. "Invalid form: " (tostring tgt) " is not a list")))
(let [new-list (list)]
(each [i v (ipairs tgt)]
(table.insert new-list (mapper v i tgt)))
new-list))
:list-map-recursive
(fn list-map-recursive [mapper tgt i]
(list-map
(fn recursive-mapper [v i tgt]
(if
(list? v) (list-map-recursive recursive-mapper v)
(mapper v i tgt)))
tgt))})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment