From dd50aef68f136d33974f7a50de94f396dfd82125 Mon Sep 17 00:00:00 2001 From: Sean Walker Date: Fri, 10 Jan 2020 23:37:06 -0700 Subject: [PATCH] Add rest macro --- src/joy/helper.janet | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/joy/helper.janet b/src/joy/helper.janet index 58ecbfc..cda76cc 100644 --- a/src/joy/helper.janet +++ b/src/joy/helper.janet @@ -144,3 +144,16 @@ (array? val) (array/slice val 0 (dec (length val))) (tuple? val) (tuple/slice val 0 (dec (length val))) :else @[])) + + +(defmacro rest + `Returns all but the first element in an array/tuple. + Does not maintain input (array or tuple) data structure, + always returns a tuple. Throws on nil. + + Example + + (rest @[1 2 3]) => (2 3) + (rest [3 2 1]) => (2 1)` + [indexed] + ~(drop 1 ,indexed))