Created
May 10, 2019 03:39
-
-
Save jaawerth/42e84e30e9f87715e3d728774541b952 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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