From 585ac9cc3464c4ba8af6497078162aaf6c6b8dce Mon Sep 17 00:00:00 2001 From: narimiran Date: Sun, 22 Oct 2017 14:35:17 +0200 Subject: change seq name to `list` --- lib/pure/collections/sequtils.nim | 151 +++++++++++++++++++------------------- 1 file changed, 76 insertions(+), 75 deletions(-) diff --git a/lib/pure/collections/sequtils.nim b/lib/pure/collections/sequtils.nim index 0cc367fa7..850f130c0 100644 --- a/lib/pure/collections/sequtils.nim +++ b/lib/pure/collections/sequtils.nim @@ -57,8 +57,8 @@ proc count*[T](list: seq[T], item: T): int = if x == item: inc result -proc cycle*[T](s: seq[T], n: Natural): seq[T] = - ## Returns a new sequence with the items of `s` repeated `n` times. +proc cycle*[T](list: seq[T], n: Natural): seq[T] = + ## Returns a new sequence with the items of `list` repeated `n` times. ## ## Example: ## @@ -68,15 +68,15 @@ proc cycle*[T](s: seq[T], n: Natural): seq[T] = ## s = @[1, 2, 3] ## total = s.cycle(3) ## assert total == @[1, 2, 3, 1, 2, 3, 1, 2, 3] - result = newSeq[T](n * s.len) + result = newSeq[T](n * list.len) var o = 0 - for x in 0..`_ proc. The proc will assert in debug + ## inverse of the `concat <#concat>`_ proc. The proc will assert in debug ## builds if `s` is nil or `num` is less than one, and will likely crash on ## release builds. The input sequence `s` can be empty, which will produce ## `num` empty sequences. @@ -154,9 +155,9 @@ proc distribute*[T](s: seq[T], num: Positive, spread = true): seq[seq[T]] = ## assert numbers.distribute(3, false) == @[@[1, 2, 3], @[4, 5, 6], @[7]] ## assert numbers.distribute(6)[0] == @[1, 2] ## assert numbers.distribute(6)[5] == @[7] - assert(not s.isNil, "`s` can't be nil") + assert(not list.isNil, "`list` can't be nil") if num < 2: - result = @[s] + result = @[list] return let num = int(num) # XXX probably only needed because of .. bug @@ -164,10 +165,10 @@ proc distribute*[T](s: seq[T], num: Positive, spread = true): seq[seq[T]] = # Create the result and calculate the stride size and the remainder if any. result = newSeq[seq[T]](num) var - stride = s.len div num + stride = list.len div num first = 0 last = 0 - extra = s.len mod num + extra = list.len mod num if extra == 0 or spread == false: # Use an algorithm which overcounts the stride and minimizes reading limits. @@ -175,8 +176,8 @@ proc distribute*[T](s: seq[T], num: Positive, spread = true): seq[seq[T]] = for i in 0 .. ["142", "242", "342", "442"] ## **Deprecated since version 0.12.0:** Use the ``apply`` proc instead. - for i in 0..data.len-1: op(data[i]) + for i in 0 .. ["142", "242", "342", "442"] ## - for i in 0..data.len-1: op(data[i]) + for i in 0 .. ["142", "242", "342", "442"] ## - for i in 0..data.len-1: data[i] = op(data[i]) + for i in 0 .. 10) ## assert floats == @[13.0, 12.5, 10.1] var pos = 0 - for i in 0 .. 50 or it < -10) ## assert acceptable == @[-2.0, 24.5, 44.31] ## assert notAcceptable == @[-272.15, 99.9, -113.44] - var result = newSeq[type(seq1[0])]() - for it {.inject.} in items(seq1): + var result = newSeq[type(list[0])]() + for it {.inject.} in items(list): if pred: result.add(it) result @@ -407,7 +408,7 @@ template keepItIf*(varSeq: seq, pred: untyped) = inc(pos) setLen(varSeq, pos) -proc all*[T](seq1: seq[T], pred: proc(item: T): bool {.closure.}): bool = +proc all*[T](list: seq[T], pred: proc(item: T): bool {.closure.}): bool = ## Iterates through a sequence and checks if every item fulfills the ## predicate. ## @@ -417,12 +418,12 @@ proc all*[T](seq1: seq[T], pred: proc(item: T): bool {.closure.}): bool = ## let numbers = @[1, 4, 5, 8, 9, 7, 4] ## assert all(numbers, proc (x: int): bool = return x < 10) == true ## assert all(numbers, proc (x: int): bool = return x < 9) == false - for i in seq1: + for i in list: if not pred(i): return false return true -template allIt*(seq1, pred: untyped): bool = +template allIt*(list, pred: untyped): bool = ## Checks if every item fulfills the predicate. ## ## Example: @@ -432,13 +433,13 @@ template allIt*(seq1, pred: untyped): bool = ## assert allIt(numbers, it < 10) == true ## assert allIt(numbers, it < 9) == false var result = true - for it {.inject.} in items(seq1): + for it {.inject.} in items(list): if not pred: result = false break result -proc any*[T](seq1: seq[T], pred: proc(item: T): bool {.closure.}): bool = +proc any*[T](list: seq[T], pred: proc(item: T): bool {.closure.}): bool = ## Iterates through a sequence and checks if some item fulfills the ## predicate. ## @@ -448,12 +449,12 @@ proc any*[T](seq1: seq[T], pred: proc(item: T): bool {.closure.}): bool = ## let numbers = @[1, 4, 5, 8, 9, 7, 4] ## assert any(numbers, proc (x: int): bool = return x > 8) == true ## assert any(numbers, proc (x: int): bool = return x > 9) == false - for i in seq1: + for i in list: if pred(i): return true return false -template anyIt*(seq1, pred: untyped): bool = +template anyIt*(list, pred: untyped): bool = ## Checks if some item fulfills the predicate. ## ## Example: @@ -463,7 +464,7 @@ template anyIt*(seq1, pred: untyped): bool = ## assert anyIt(numbers, it > 8) == true ## assert anyIt(numbers, it > 9) == false var result = false - for it {.inject.} in items(seq1): + for it {.inject.} in items(list): if pred: result = true break @@ -594,7 +595,7 @@ template foldr*(sequence, operation: untyped): untyped = result = operation result -template mapIt*(seq1, typ, op: untyped): untyped = +template mapIt*(list, typ, op: untyped): untyped = ## Convenience template around the ``map`` proc to reduce typing. ## ## The template injects the ``it`` variable which you can use directly in an @@ -610,12 +611,12 @@ template mapIt*(seq1, typ, op: untyped): untyped = ## **Deprecated since version 0.12.0:** Use the ``mapIt(seq1, op)`` ## template instead. var result: seq[typ] = @[] - for it {.inject.} in items(seq1): + for it {.inject.} in items(list): result.add(op) result -template mapIt*(seq1, op: untyped): untyped = +template mapIt*(list, op: untyped): untyped = ## Convenience template around the ``map`` proc to reduce typing. ## ## The template injects the ``it`` variable which you can use directly in an @@ -628,11 +629,11 @@ template mapIt*(seq1, op: untyped): untyped = ## assert strings == @["4", "8", "12", "16"] type outType = type(( block: - var it{.inject.}: type(items(seq1)); + var it{.inject.}: type(items(list)); op)) var result: seq[outType] - when compiles(seq1.len): - let s = seq1 + when compiles(list.len): + let s = list var i = 0 result = newSeq[outType](s.len) for it {.inject.} in s: @@ -640,7 +641,7 @@ template mapIt*(seq1, op: untyped): untyped = i += 1 else: result = @[] - for it {.inject.} in seq1: + for it {.inject.} in list: result.add(op) result -- cgit 1.4.1-2-gfad0 From e73adde803c0305ab1a5e3b1d42e58721b24eded Mon Sep 17 00:00:00 2001 From: narimiran Date: Sun, 22 Oct 2017 14:46:58 +0200 Subject: update links --- lib/pure/collections/sequtils.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pure/collections/sequtils.nim b/lib/pure/collections/sequtils.nim index 850f130c0..83c52e7a9 100644 --- a/lib/pure/collections/sequtils.nim +++ b/lib/pure/collections/sequtils.nim @@ -13,8 +13,8 @@ ## were inspired by functional programming languages. ## ## For functional style programming you may want to pass `anonymous procs -## `_ to procs like ``filter`` to reduce typing. -## Anonymous procs can use `the special do notation `_ +## `_ to procs like ``filter`` to reduce typing. +## Anonymous procs can use `the special do notation `_ ## which is more convenient in certain situations. include "system/inclrtl" -- cgit 1.4.1-2-gfad0