t5968.nim 347 B

123456789101112131415161718192021
  1. discard """
  2. exitcode: 0
  3. """
  4. type
  5. Enumerable[T] = concept e
  6. for it in e:
  7. it is T
  8. proc cmap[T, G](e: Enumerable[T], fn: proc(t: T): G): seq[G] =
  9. result = @[]
  10. for it in e: result.add(fn(it))
  11. import json
  12. var x = %["hello", "world"]
  13. var z = x.cmap(proc(it: JsonNode): string = it.getStr & "!")
  14. assert z == @["hello!", "world!"]