Skip to content

Commit

Permalink
commented out map2 to focus this PR on lambda addition only
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Aug 21, 2018
1 parent 988088a commit b74addd
Showing 1 changed file with 31 additions and 29 deletions.
60 changes: 31 additions & 29 deletions lib/pure/collections/sequtils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -640,34 +640,35 @@ template foldr*(sequence, operation: untyped): untyped =
result = operation
result

template map2*(s, lambda: untyped): untyped =
## like ``mapIt`` but with cleaner syntax: ``[1,2].mapIt(a => a*10)``
runnableExamples:
doAssert [1,2].map2(a=>a*10) == @[10,20]
let foo=3
doAssert [1,2].map2(a=>a*foo) == @[3,6]
makeLambda(lambda, lambda2)
type outType = type((
block:
var it: type(items(s))
lambda2(it)
))

when compiles(s.len):
var result: seq[outType]
block:
evalOnceAs(s2, s, compiles((let _ = s)))
var i = 0
var result = newSeq[outType](s2.len)
for it in s2:
result[i] = lambda2(it)
i += 1
when false:
template map2*(s, lambda: untyped): untyped =
## like ``mapIt`` but with cleaner syntax: ``[1,2].mapIt(a => a*10)``
runnableExamples:
doAssert [1,2].map2(a=>a*10) == @[10,20]
let foo=3
doAssert [1,2].map2(a=>a*foo) == @[3,6]
makeLambda(lambda, lambda2)
type outType = type((
block:
var it: type(items(s))
lambda2(it)
))

when compiles(s.len):
var result: seq[outType]
block:
evalOnceAs(s2, s, compiles((let _ = s)))
var i = 0
var result = newSeq[outType](s2.len)
for it in s2:
result[i] = lambda2(it)
i += 1
result
else:
var result: seq[outType] = @[]
for it in s:
result.add lambda2(it)
result
else:
var result: seq[outType] = @[]
for it in s:
result.add lambda2(it)
result

template mapIt*(s, typ, op: untyped): untyped =
## Convenience template around the ``map`` proc to reduce typing.
Expand Down Expand Up @@ -1170,5 +1171,6 @@ when isMainModule:
echo "Finished doc tests"

block map2Test:
# PENDING https://github.com/nim-lang/Nim/issues/7280
discard [1].map2(a => a)
when false:
# PENDING https://github.com/nim-lang/Nim/issues/7280
discard [1].map2(a => a)

0 comments on commit b74addd

Please sign in to comment.