From 2bdd2fab6e9bdcdcb51ea7e09d077f36a29faf4c Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Wed, 2 Oct 2019 16:24:59 +0300 Subject: [PATCH] Add `len` for tuples --- stew/objects.nim | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/stew/objects.nim b/stew/objects.nim index 3307f6d..01b0f6a 100644 --- a/stew/objects.nim +++ b/stew/objects.nim @@ -24,3 +24,10 @@ proc toArray*[T](N: static int, data: openarray[T]): array[N, T] = template anonConst*(val: untyped): untyped = const c = val c + +when not compiles(len((1, 2))): + import typetraits + + func len*(x: tuple): int = + arity(type(x)) +