diff options
author | Amjad Ben Hedhili <amjadhedhili@outlook.com> | 2022-09-19 22:43:46 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-19 17:43:46 -0400 |
commit | 7023176dcbc557907f5842f0a4f90b5774735e1e (patch) | |
tree | 4937a89028d6d26b61f1a7fdd911fa452eb27a8d | |
parent | 7a756bfaef29ff521059b3310b67a0344001f5fd (diff) | |
download | Nim-7023176dcbc557907f5842f0a4f90b5774735e1e.tar.gz |
Recommend `mapIt` in some cases (#20347)
* Recommend `mapIt` in some cases * Remove runnableExample
-rw-r--r-- | lib/pure/sugar.nim | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/lib/pure/sugar.nim b/lib/pure/sugar.nim index d7beef8d9..ff2a3bb58 100644 --- a/lib/pure/sugar.nim +++ b/lib/pure/sugar.nim @@ -391,6 +391,10 @@ macro collect*(init, body: untyped): untyped {.since: (1, 1).} = macro collect*(body: untyped): untyped {.since: (1, 5).} = ## Same as `collect` but without an `init` parameter. + ## + ## **See also:** + ## * `sequtils.toSeq proc<sequtils.html#toSeq.t%2Cuntyped>`_ + ## * `sequtils.mapIt template<sequtils.html#mapIt.t%2Ctyped%2Cuntyped>`_ runnableExamples: import std/[sets, tables] let data = @["bird", "word"] @@ -411,10 +415,4 @@ macro collect*(body: untyped): untyped {.since: (1, 5).} = for i, d in data.pairs: {i: d} assert m == {0: "bird", 1: "word"}.toTable - # avoid `collect` when `sequtils.toSeq` suffices: - assert collect(for i in 1..3: i*i) == @[1, 4, 9] # ok in this case - assert collect(for i in 1..3: i) == @[1, 2, 3] # overkill in this case - from std/sequtils import toSeq - assert toSeq(1..3) == @[1, 2, 3] # simpler - result = collectImpl(nil, body) |