diff options
-rw-r--r-- | lib/pure/typetraits.nim | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/pure/typetraits.nim b/lib/pure/typetraits.nim index e9579e824..c53b68864 100644 --- a/lib/pure/typetraits.nim +++ b/lib/pure/typetraits.nim @@ -35,8 +35,13 @@ proc `$`*(t: typedesc): string = ## An alias for `name`. name(t) -proc arity*(t: typedesc): int {.magic: "TypeTrait".} - ## Returns the arity of the given type +proc arity*(t: typedesc): int {.magic: "TypeTrait".} = + ## Returns the arity of the given type. This is the number of "type" components or + ## the number of generic parameters a given type ``t`` has. + runnableExamples: + assert arity(seq[string]) == 1 + assert arity(array[3, int]) == 2 + assert arity((int, int, float, string)) == 4 proc genericHead*(t: typedesc): typedesc {.magic: "TypeTrait".} ## Accepts an instantiated generic type and returns its @@ -47,11 +52,11 @@ proc genericHead*(t: typedesc): typedesc {.magic: "TypeTrait".} ## seq[int].genericHead[float] will be seq[float] ## ## A compile-time error will be produced if the supplied type - ## is not generic + ## is not generic. proc stripGenericParams*(t: typedesc): typedesc {.magic: "TypeTrait".} ## This trait is similar to `genericHead`, but instead of producing - ## error for non-generic types, it will just return them unmodified + ## error for non-generic types, it will just return them unmodified. proc supportsCopyMem*(t: typedesc): bool {.magic: "TypeTrait".} ## This trait returns true iff the type ``t`` is safe to use for |