added system.typeof operation; fixes #9093
This commit is contained in:
parent
e7e75224a2
commit
963292f725
5 changed files with 47 additions and 4 deletions
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue