Skip to content

Instantly share code, notes, and snippets.

@disco0
Forked from jaawerth/list-map.fnl
Created June 9, 2021 06:57
Show Gist options
  • Save disco0/b077315764310c27ba46709d3125084a to your computer and use it in GitHub Desktop.
Save disco0/b077315764310c27ba46709d3125084a 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