Rename keepIfIt to keepItIf
This commit is contained in:
parent
92e958b654
commit
f6c4864f9f
1 changed files with 5 additions and 5 deletions
|
|
@ -270,16 +270,16 @@ template filterIt*(seq1, pred: expr): expr {.immediate.} =
|
||||||
if pred: result.add(it)
|
if pred: result.add(it)
|
||||||
result
|
result
|
||||||
|
|
||||||
template keepIfIt*(varSeq, pred: expr) =
|
template keepItIf*(varSeq, pred: expr) =
|
||||||
## Convenience template around the ``keepIf`` proc to reduce typing.
|
## Convenience template around the ``keepIf`` proc to reduce typing.
|
||||||
##
|
##
|
||||||
## Unlike the `proc` version, the predicate needs to be an expression using
|
## Unlike the `proc` version, the predicate needs to be an expression using
|
||||||
## the ``it`` variable for testing, like: ``keepIfIt("abcxyz", it == 'x')``.
|
## the ``it`` variable for testing, like: ``keepItIf("abcxyz", it == 'x')``.
|
||||||
## Example:
|
## Example:
|
||||||
##
|
##
|
||||||
## .. code-block:: nimrod
|
## .. code-block:: nimrod
|
||||||
## var candidates = @["foo", "bar", "baz", "foobar"]
|
## var candidates = @["foo", "bar", "baz", "foobar"]
|
||||||
## keepIfIt(candidates, it.len == 3 and it[0] == 'b')
|
## keepItIf(candidates, it.len == 3 and it[0] == 'b')
|
||||||
## assert candidates == @["bar", "baz"]
|
## assert candidates == @["bar", "baz"]
|
||||||
var pos = 0
|
var pos = 0
|
||||||
for i in 0 .. <len(varSeq):
|
for i in 0 .. <len(varSeq):
|
||||||
|
|
@ -470,9 +470,9 @@ when isMainModule:
|
||||||
assert acceptable == @[-2.0, 24.5, 44.31]
|
assert acceptable == @[-2.0, 24.5, 44.31]
|
||||||
assert notAcceptable == @[-272.15, 99.9, -113.44]
|
assert notAcceptable == @[-272.15, 99.9, -113.44]
|
||||||
|
|
||||||
block: # keepIfIt test
|
block: # keepItIf test
|
||||||
var candidates = @["foo", "bar", "baz", "foobar"]
|
var candidates = @["foo", "bar", "baz", "foobar"]
|
||||||
keepIfIt(candidates, it.len == 3 and it[0] == 'b')
|
keepItIf(candidates, it.len == 3 and it[0] == 'b')
|
||||||
assert candidates == @["bar", "baz"]
|
assert candidates == @["bar", "baz"]
|
||||||
|
|
||||||
block: # toSeq test
|
block: # toSeq test
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue