Skip to content

Commit

Permalink
sequtils.nim: Use func (#16293)
Browse files Browse the repository at this point in the history
* sequtils.nim: proc -> func

* sequtils.nim: proc -> func in links

* sequtils.nim: proc -> func in non-link doc comments

* test: add `sequtils` to strictFuncs test
  • Loading branch information
ee7 authored Dec 9, 2020
1 parent c43dca2 commit 6f57eba
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 47 deletions.
92 changes: 46 additions & 46 deletions lib/pure/collections/sequtils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ macro evalOnceAs(expAlias, exp: untyped,
newProc(name = genSym(nskTemplate, $expAlias), params = [getType(untyped)],
body = val, procType = nnkTemplateDef))

proc concat*[T](seqs: varargs[seq[T]]): seq[T] =
func concat*[T](seqs: varargs[seq[T]]): seq[T] =
## Takes several sequences' items and returns them inside a new sequence.
## All sequences must be of the same type.
##
## See also:
## * `distribute proc<#distribute,seq[T],Positive>`_ for a reverse
## * `distribute func<#distribute,seq[T],Positive>`_ for a reverse
## operation
##
runnableExamples:
Expand All @@ -135,7 +135,7 @@ proc concat*[T](seqs: varargs[seq[T]]): seq[T] =
result[i] = itm
inc(i)

proc count*[T](s: openArray[T], x: T): int =
func count*[T](s: openArray[T], x: T): int =
## Returns the number of occurrences of the item `x` in the container `s`.
##
runnableExamples:
Expand All @@ -150,7 +150,7 @@ proc count*[T](s: openArray[T], x: T): int =
if itm == x:
inc result

proc cycle*[T](s: openArray[T], n: Natural): seq[T] =
func cycle*[T](s: openArray[T], n: Natural): seq[T] =
## Returns a new sequence with the items of the container `s` repeated
## `n` times.
## `n` must be a non-negative number (zero or more).
Expand All @@ -168,7 +168,7 @@ proc cycle*[T](s: openArray[T], n: Natural): seq[T] =
result[o] = e
inc o

proc repeat*[T](x: T, n: Natural): seq[T] =
func repeat*[T](x: T, n: Natural): seq[T] =
## Returns a new sequence with the item `x` repeated `n` times.
## `n` must be a non-negative number (zero or more).
##
Expand All @@ -181,7 +181,7 @@ proc repeat*[T](x: T, n: Natural): seq[T] =
for i in 0 ..< n:
result[i] = x

proc deduplicate*[T](s: openArray[T], isSorted: bool = false): seq[T] =
func deduplicate*[T](s: openArray[T], isSorted: bool = false): seq[T] =
## Returns a new sequence without duplicates.
##
## Setting the optional argument ``isSorted`` to ``true`` (default: false)
Expand Down Expand Up @@ -209,7 +209,7 @@ proc deduplicate*[T](s: openArray[T], isSorted: bool = false): seq[T] =
for itm in items(s):
if not result.contains(itm): result.add(itm)

proc minIndex*[T](s: openArray[T]): int {.since: (1, 1).} =
func minIndex*[T](s: openArray[T]): int {.since: (1, 1).} =
## Returns the index of the minimum value of `s`.
## ``T`` needs to have a ``<`` operator.
runnableExamples:
Expand All @@ -226,7 +226,7 @@ proc minIndex*[T](s: openArray[T]): int {.since: (1, 1).} =
for i in 1..high(s):
if s[i] < s[result]: result = i

proc maxIndex*[T](s: openArray[T]): int {.since: (1, 1).} =
func maxIndex*[T](s: openArray[T]): int {.since: (1, 1).} =
## Returns the index of the maximum value of `s`.
## ``T`` needs to have a ``<`` operator.
runnableExamples:
Expand All @@ -245,7 +245,7 @@ proc maxIndex*[T](s: openArray[T]): int {.since: (1, 1).} =


template zipImpl(s1, s2, retType: untyped): untyped =
proc zip*[S, T](s1: openArray[S], s2: openArray[T]): retType =
func zip*[S, T](s1: openArray[S], s2: openArray[T]): retType =
## Returns a new sequence with a combination of the two input containers.
##
## The input containers can be of different types.
Expand Down Expand Up @@ -288,7 +288,7 @@ when (NimMajor, NimMinor) <= (1, 0):
else:
zipImpl(s1, s2, seq[(S, T)])

proc unzip*[S, T](s: openArray[(S, T)]): (seq[S], seq[T]) {.since: (1, 1).} =
func unzip*[S, T](s: openArray[(S, T)]): (seq[S], seq[T]) {.since: (1, 1).} =
## Returns a tuple of two sequences split out from a sequence of 2-field tuples.
runnableExamples:
let
Expand All @@ -303,19 +303,19 @@ proc unzip*[S, T](s: openArray[(S, T)]): (seq[S], seq[T]) {.since: (1, 1).} =
result[0][i] = s[i][0]
result[1][i] = s[i][1]

proc distribute*[T](s: seq[T], num: Positive, spread = true): seq[seq[T]] =
func distribute*[T](s: seq[T], num: Positive, spread = true): seq[seq[T]] =
## Splits and distributes a sequence `s` into `num` sub-sequences.
##
## Returns a sequence of `num` sequences. For *some* input values this is the
## inverse of the `concat <#concat,varargs[seq[T]]>`_ proc.
## inverse of the `concat <#concat,varargs[seq[T]]>`_ func.
## The input sequence `s` can be empty, which will produce
## `num` empty sequences.
##
## If `spread` is false and the length of `s` is not a multiple of `num`, the
## proc will max out the first sub-sequence with ``1 + len(s) div num``
## func will max out the first sub-sequence with ``1 + len(s) div num``
## entries, leaving the remainder of elements to the last sequence.
##
## On the other hand, if `spread` is true, the proc will distribute evenly
## On the other hand, if `spread` is true, the func will distribute evenly
## the remainder of the division across all sequences, which makes the result
## more suited to multithreading where you are passing equal sized work units
## to a thread pool and want to maximize core usage.
Expand Down Expand Up @@ -360,7 +360,7 @@ proc distribute*[T](s: seq[T], num: Positive, spread = true): seq[seq[T]] =
result[i].add(s[g])
first = last

proc map*[T, S](s: openArray[T], op: proc (x: T): S {.closure.}):
func map*[T, S](s: openArray[T], op: proc (x: T): S {.closure.}):
seq[S]{.inline.} =
## Returns a new sequence with the results of `op` proc applied to every
## item in the container `s`.
Expand All @@ -374,7 +374,7 @@ proc map*[T, S](s: openArray[T], op: proc (x: T): S {.closure.}):
## See also:
## * `sugar.collect macro<sugar.html#collect.m%2Cuntyped%2Cuntyped>`_
## * `mapIt template<#mapIt.t,typed,untyped>`_
## * `apply proc<#apply,openArray[T],proc(T)_2>`_ for the in-place version
## * `apply func<#apply,openArray[T],proc(T)_2>`_ for the in-place version
##
runnableExamples:
let
Expand All @@ -386,7 +386,7 @@ proc map*[T, S](s: openArray[T], op: proc (x: T): S {.closure.}):
for i in 0 ..< s.len:
result[i] = op(s[i])

proc apply*[T](s: var openArray[T], op: proc (x: var T) {.closure.})
func apply*[T](s: var openArray[T], op: proc (x: var T) {.closure.})
{.inline.} =
## Applies `op` to every item in `s` modifying it directly.
##
Expand All @@ -397,7 +397,7 @@ proc apply*[T](s: var openArray[T], op: proc (x: var T) {.closure.})
##
## See also:
## * `applyIt template<#applyIt.t,untyped,untyped>`_
## * `map proc<#map,openArray[T],proc(T)>`_
## * `map func<#map,openArray[T],proc(T)>`_
##
runnableExamples:
var a = @["1", "2", "3", "4"]
Expand All @@ -406,7 +406,7 @@ proc apply*[T](s: var openArray[T], op: proc (x: var T) {.closure.})

for i in 0 ..< s.len: op(s[i])

proc apply*[T](s: var openArray[T], op: proc (x: T): T {.closure.})
func apply*[T](s: var openArray[T], op: proc (x: T): T {.closure.})
{.inline.} =
## Applies `op` to every item in `s` modifying it directly.
##
Expand All @@ -417,7 +417,7 @@ proc apply*[T](s: var openArray[T], op: proc (x: T): T {.closure.})
##
## See also:
## * `applyIt template<#applyIt.t,untyped,untyped>`_
## * `map proc<#map,openArray[T],proc(T)>`_
## * `map func<#map,openArray[T],proc(T)>`_
##
runnableExamples:
var a = @["1", "2", "3", "4"]
Expand All @@ -426,7 +426,7 @@ proc apply*[T](s: var openArray[T], op: proc (x: T): T {.closure.})

for i in 0 ..< s.len: s[i] = op(s[i])

proc apply*[T](s: openArray[T], op: proc (x: T) {.closure.}) {.inline, since: (1, 3).} =
func apply*[T](s: openArray[T], op: proc (x: T) {.closure.}) {.inline, since: (1, 3).} =
## Same as `apply` but for proc that do not return and do not mutate `s` directly.
runnableExamples: apply([0, 1, 2, 3, 4], proc(item: int) = echo item)
for i in 0 ..< s.len: op(s[i])
Expand All @@ -440,7 +440,7 @@ iterator filter*[T](s: openArray[T], pred: proc(x: T): bool {.closure.}): T =
##
## See also:
## * `sugar.collect macro<sugar.html#collect.m%2Cuntyped%2Cuntyped>`_
## * `fliter proc<#filter,openArray[T],proc(T)>`_
## * `fliter func<#filter,openArray[T],proc(T)>`_
## * `filterIt template<#filterIt.t,untyped,untyped>`_
##
runnableExamples:
Expand All @@ -454,7 +454,7 @@ iterator filter*[T](s: openArray[T], pred: proc(x: T): bool {.closure.}): T =
if pred(s[i]):
yield s[i]

proc filter*[T](s: openArray[T], pred: proc(x: T): bool {.closure.}): seq[T]
func filter*[T](s: openArray[T], pred: proc(x: T): bool {.closure.}): seq[T]
{.inline.} =
## Returns a new sequence with all the items of `s` that fulfilled the
## predicate `pred` (function that returns a `bool`).
Expand All @@ -466,7 +466,7 @@ proc filter*[T](s: openArray[T], pred: proc(x: T): bool {.closure.}): seq[T]
## * `sugar.collect macro<sugar.html#collect.m%2Cuntyped%2Cuntyped>`_
## * `filterIt template<#filterIt.t,untyped,untyped>`_
## * `filter iterator<#filter.i,openArray[T],proc(T)>`_
## * `keepIf proc<#keepIf,seq[T],proc(T)>`_ for the in-place version
## * `keepIf func<#keepIf,seq[T],proc(T)>`_ for the in-place version
##
runnableExamples:
let
Expand All @@ -481,19 +481,19 @@ proc filter*[T](s: openArray[T], pred: proc(x: T): bool {.closure.}): seq[T]
if pred(s[i]):
result.add(s[i])

proc keepIf*[T](s: var seq[T], pred: proc(x: T): bool {.closure.})
func keepIf*[T](s: var seq[T], pred: proc(x: T): bool {.closure.})
{.inline.} =
## Keeps the items in the passed sequence `s` if they fulfilled the
## predicate `pred` (function that returns a `bool`).
##
## Note that `s` must be declared as a ``var``.
##
## Similar to the `filter proc<#filter,openArray[T],proc(T)>`_,
## Similar to the `filter func<#filter,openArray[T],proc(T)>`_,
## but modifies the sequence directly.
##
## See also:
## * `keepItIf template<#keepItIf.t,seq,untyped>`_
## * `filter proc<#filter,openArray[T],proc(T)>`_
## * `filter func<#filter,openArray[T],proc(T)>`_
##
runnableExamples:
var floats = @[13.0, 12.5, 5.8, 2.0, 6.1, 9.9, 10.1]
Expand All @@ -511,7 +511,7 @@ proc keepIf*[T](s: var seq[T], pred: proc(x: T): bool {.closure.})
inc(pos)
setLen(s, pos)

proc delete*[T](s: var seq[T]; first, last: Natural) =
func delete*[T](s: var seq[T]; first, last: Natural) =
## Deletes in the items of a sequence `s` at positions ``first..last``
## (including both ends of a range).
## This modifies `s` itself, it does not return a copy.
Expand All @@ -536,7 +536,7 @@ proc delete*[T](s: var seq[T]; first, last: Natural) =
inc(j)
setLen(s, newLen)

proc insert*[T](dest: var seq[T], src: openArray[T], pos = 0) =
func insert*[T](dest: var seq[T], src: openArray[T], pos = 0) =
## Inserts items from `src` into `dest` at position `pos`. This modifies
## `dest` itself, it does not return a copy.
##
Expand Down Expand Up @@ -574,7 +574,7 @@ template filterIt*(s, pred: untyped): untyped =
## Returns a new sequence with all the items of `s` that fulfilled the
## predicate `pred`.
##
## Unlike the `filter proc<#filter,openArray[T],proc(T)>`_ and
## Unlike the `filter func<#filter,openArray[T],proc(T)>`_ and
## `filter iterator<#filter.i,openArray[T],proc(T)>`_,
## the predicate needs to be an expression using the ``it`` variable
## for testing, like: ``filterIt("abcxyz", it == 'x')``.
Expand All @@ -584,7 +584,7 @@ template filterIt*(s, pred: untyped): untyped =
##
## See also:
## * `sugar.collect macro<sugar.html#collect.m%2Cuntyped%2Cuntyped>`_
## * `fliter proc<#filter,openArray[T],proc(T)>`_
## * `fliter func<#filter,openArray[T],proc(T)>`_
## * `filter iterator<#filter.i,openArray[T],proc(T)>`_
##
runnableExamples:
Expand All @@ -604,12 +604,12 @@ template keepItIf*(varSeq: seq, pred: untyped) =
## Keeps the items in the passed sequence (must be declared as a ``var``)
## if they fulfilled the predicate.
##
## Unlike the `keepIf proc<#keepIf,seq[T],proc(T)>`_,
## Unlike the `keepIf func<#keepIf,seq[T],proc(T)>`_,
## the predicate needs to be an expression using
## the ``it`` variable for testing, like: ``keepItIf("abcxyz", it == 'x')``.
##
## See also:
## * `keepIf proc<#keepIf,seq[T],proc(T)>`_
## * `keepIf func<#keepIf,seq[T],proc(T)>`_
## * `filterIt template<#filterIt.t,untyped,untyped>`_
##
runnableExamples:
Expand Down Expand Up @@ -648,13 +648,13 @@ since (1, 1):
if pred: result += 1
result

proc all*[T](s: openArray[T], pred: proc(x: T): bool {.closure.}): bool =
func all*[T](s: openArray[T], pred: proc(x: T): bool {.closure.}): bool =
## Iterates through a container and checks if every item fulfills the
## predicate.
##
## See also:
## * `allIt template<#allIt.t,untyped,untyped>`_
## * `any proc<#any,openArray[T],proc(T)>`_
## * `any func<#any,openArray[T],proc(T)>`_
##
runnableExamples:
let numbers = @[1, 4, 5, 8, 9, 7, 4]
Expand All @@ -670,12 +670,12 @@ template allIt*(s, pred: untyped): bool =
## Iterates through a container and checks if every item fulfills the
## predicate.
##
## Unlike the `all proc<#all,openArray[T],proc(T)>`_,
## Unlike the `all func<#all,openArray[T],proc(T)>`_,
## the predicate needs to be an expression using
## the ``it`` variable for testing, like: ``allIt("abba", it == 'a')``.
##
## See also:
## * `all proc<#all,openArray[T],proc(T)>`_
## * `all func<#all,openArray[T],proc(T)>`_
## * `anyIt template<#anyIt.t,untyped,untyped>`_
##
runnableExamples:
Expand All @@ -690,13 +690,13 @@ template allIt*(s, pred: untyped): bool =
break
result

proc any*[T](s: openArray[T], pred: proc(x: T): bool {.closure.}): bool =
func any*[T](s: openArray[T], pred: proc(x: T): bool {.closure.}): bool =
## Iterates through a container and checks if some item fulfills the
## predicate.
##
## See also:
## * `anyIt template<#anyIt.t,untyped,untyped>`_
## * `all proc<#all,openArray[T],proc(T)>`_
## * `all func<#all,openArray[T],proc(T)>`_
##
runnableExamples:
let numbers = @[1, 4, 5, 8, 9, 7, 4]
Expand All @@ -712,12 +712,12 @@ template anyIt*(s, pred: untyped): bool =
## Iterates through a container and checks if some item fulfills the
## predicate.
##
## Unlike the `any proc<#any,openArray[T],proc(T)>`_,
## Unlike the `any func<#any,openArray[T],proc(T)>`_,
## the predicate needs to be an expression using
## the ``it`` variable for testing, like: ``anyIt("abba", it == 'a')``.
##
## See also:
## * `any proc<#any,openArray[T],proc(T)>`_
## * `any func<#any,openArray[T],proc(T)>`_
## * `allIt template<#allIt.t,untyped,untyped>`_
##
runnableExamples:
Expand Down Expand Up @@ -840,7 +840,7 @@ template foldl*(sequence, operation: untyped): untyped =
procs = @["proc", "Is", "Also", "Fine"]


proc foo(acc, cur: string): string =
func foo(acc, cur: string): string =
result = acc & cur

assert addition == 25, "Addition is (((5)+9)+11)"
Expand Down Expand Up @@ -944,7 +944,7 @@ template mapIt*(s: typed, op: untyped): untyped =
##
## See also:
## * `sugar.collect macro<sugar.html#collect.m%2Cuntyped%2Cuntyped>`_
## * `map proc<#map,openArray[T],proc(T)>`_
## * `map func<#map,openArray[T],proc(T)>`_
## * `applyIt template<#applyIt.t,untyped,untyped>`_ for the in-place version
##
runnableExamples:
Expand Down Expand Up @@ -1005,14 +1005,14 @@ template mapIt*(s: typed, op: untyped): untyped =
map(s, f)

template applyIt*(varSeq, op: untyped) =
## Convenience template around the mutable ``apply`` proc to reduce typing.
## Convenience template around the mutable ``apply`` func to reduce typing.
##
## The template injects the ``it`` variable which you can use directly in an
## expression. The expression has to return the same type as the sequence you
## are mutating.
##
## See also:
## * `apply proc<#apply,openArray[T],proc(T)_2>`_
## * `apply func<#apply,openArray[T],proc(T)_2>`_
## * `mapIt template<#mapIt.t,typed,untyped>`_
##
runnableExamples:
Expand Down Expand Up @@ -1048,7 +1048,7 @@ template newSeqWith*(len: int, init: untyped): untyped =
result[i] = init
result

proc mapLitsImpl(constructor: NimNode; op: NimNode; nested: bool;
func mapLitsImpl(constructor: NimNode; op: NimNode; nested: bool;
filter = nnkLiterals): NimNode =
if constructor.kind in filter:
result = newNimNode(nnkCall, lineInfoFrom = constructor)
Expand Down
2 changes: 1 addition & 1 deletion lib/pure/collections/sets.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
##
## Common usages of sets:
## * removing duplicates from a container by converting it with `toHashSet proc
## <#toHashSet,openArray[A]>`_ (see also `sequtils.deduplicate proc
## <#toHashSet,openArray[A]>`_ (see also `sequtils.deduplicate func
## <sequtils.html#deduplicate,openArray[T],bool>`_)
## * membership testing
## * mathematical operations on two sets, such as
Expand Down
1 change: 1 addition & 0 deletions tests/effects/tstrict_funcs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import
httpcore,
math,
nre,
sequtils,
strutils,
uri

Expand Down

0 comments on commit 6f57eba

Please sign in to comment.