diff options
author | Araq <rumpf_a@web.de> | 2018-10-24 17:09:51 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2018-10-24 17:09:51 +0200 |
commit | 963292f7259798b668e5a35175bb51e9483372d1 (patch) | |
tree | b196f2b275a9e68373ed846c172e8bd0c47d9ca2 /lib/pure/collections/sequtils.nim | |
parent | e7e75224a240688c99fd62f2bcef2445ca724f3b (diff) | |
download | Nim-963292f7259798b668e5a35175bb51e9483372d1.tar.gz |
added system.typeof operation; fixes #9093
Diffstat (limited to 'lib/pure/collections/sequtils.nim')
-rw-r--r-- | lib/pure/collections/sequtils.nim | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/lib/pure/collections/sequtils.nim b/lib/pure/collections/sequtils.nim index 2e21786bb..e8ea675f5 100644 --- a/lib/pure/collections/sequtils.nim +++ b/lib/pure/collections/sequtils.nim @@ -673,10 +673,16 @@ template mapIt*(s: typed, op: untyped): untyped = ## nums = @[1, 2, 3, 4] ## strings = nums.mapIt($(4 * it)) ## assert strings == @["4", "8", "12", "16"] - type outType = type(( - block: - var it{.inject.}: type(items(s)); - op)) + when defined(nimHasTypeof): + type outType = typeof(( + block: + var it{.inject.}: typeof(items(s), typeOfIter); + op), typeOfProc) + else: + type outType = type(( + block: + var it{.inject.}: type(items(s)); + op)) when compiles(s.len): block: # using a block avoids https://github.com/nim-lang/Nim/issues/8580 @@ -1135,5 +1141,13 @@ when isMainModule: A, B doAssert mapIt(X, $it) == @["A", "B"] + block: + # bug #9093 + let inp = "a:b,c:d" + + let outp = inp.split(",").mapIt(it.split(":")) + doAssert outp == @[@["a", "b"], @["c", "d"]] + + when not defined(testing): echo "Finished doc tests" |