titerable.nim 312 B

123456789101112131415161718192021
  1. discard """
  2. nimout: "int\nint"
  3. output: 15
  4. """
  5. import typetraits
  6. type
  7. Iterable[T] = concept x
  8. for value in x:
  9. type(value) is T
  10. proc sum*[T](iter: Iterable[T]): T =
  11. static: echo T.name
  12. for element in iter:
  13. static: echo element.type.name
  14. result += element
  15. echo sum([1, 2, 3, 4, 5])