Skip to content

Commit

Permalink
sequtils.nim: Change some func back to proc
Browse files Browse the repository at this point in the history
This commit changes the funcs that take a `proc` parameter back to
procs.

This reverts some of commit 6f57eba:
  sequtils.nim: Use `func` (nim-lang#16293)

See also:
- nim-lang#16303
- nim-lang#16304
  • Loading branch information
ee7 committed Dec 10, 2020
1 parent 73299b0 commit 9137bd2
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions lib/pure/collections/sequtils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func distribute*[T](s: seq[T], num: Positive, spread = true): seq[seq[T]] =
result[i].add(s[g])
first = last

func map*[T, S](s: openArray[T], op: proc (x: T): S {.closure.}):
proc 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 @@ func 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 func<#apply,openArray[T],proc(T)_2>`_ for the in-place version
## * `apply proc<#apply,openArray[T],proc(T)_2>`_ for the in-place version
##
runnableExamples:
let
Expand All @@ -386,7 +386,7 @@ func map*[T, S](s: openArray[T], op: proc (x: T): S {.closure.}):
for i in 0 ..< s.len:
result[i] = op(s[i])

func apply*[T](s: var openArray[T], op: proc (x: var T) {.closure.})
proc 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 @@ func apply*[T](s: var openArray[T], op: proc (x: var T) {.closure.})
##
## See also:
## * `applyIt template<#applyIt.t,untyped,untyped>`_
## * `map func<#map,openArray[T],proc(T)>`_
## * `map proc<#map,openArray[T],proc(T)>`_
##
runnableExamples:
var a = @["1", "2", "3", "4"]
Expand All @@ -406,7 +406,7 @@ func apply*[T](s: var openArray[T], op: proc (x: var T) {.closure.})

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

func apply*[T](s: var openArray[T], op: proc (x: T): T {.closure.})
proc 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 @@ func apply*[T](s: var openArray[T], op: proc (x: T): T {.closure.})
##
## See also:
## * `applyIt template<#applyIt.t,untyped,untyped>`_
## * `map func<#map,openArray[T],proc(T)>`_
## * `map proc<#map,openArray[T],proc(T)>`_
##
runnableExamples:
var a = @["1", "2", "3", "4"]
Expand All @@ -426,7 +426,7 @@ func apply*[T](s: var openArray[T], op: proc (x: T): T {.closure.})

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

func apply*[T](s: openArray[T], op: proc (x: T) {.closure.}) {.inline, since: (1, 3).} =
proc 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 func<#filter,openArray[T],proc(T)>`_
## * `fliter proc<#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]

func filter*[T](s: openArray[T], pred: proc(x: T): bool {.closure.}): seq[T]
proc 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 @@ func 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 func<#keepIf,seq[T],proc(T)>`_ for the in-place version
## * `keepIf proc<#keepIf,seq[T],proc(T)>`_ for the in-place version
##
runnableExamples:
let
Expand All @@ -481,19 +481,19 @@ func filter*[T](s: openArray[T], pred: proc(x: T): bool {.closure.}): seq[T]
if pred(s[i]):
result.add(s[i])

func keepIf*[T](s: var seq[T], pred: proc(x: T): bool {.closure.})
proc 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 func<#filter,openArray[T],proc(T)>`_,
## Similar to the `filter proc<#filter,openArray[T],proc(T)>`_,
## but modifies the sequence directly.
##
## See also:
## * `keepItIf template<#keepItIf.t,seq,untyped>`_
## * `filter func<#filter,openArray[T],proc(T)>`_
## * `filter proc<#filter,openArray[T],proc(T)>`_
##
runnableExamples:
var floats = @[13.0, 12.5, 5.8, 2.0, 6.1, 9.9, 10.1]
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 func<#filter,openArray[T],proc(T)>`_ and
## Unlike the `filter proc<#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 func<#filter,openArray[T],proc(T)>`_
## * `fliter proc<#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 func<#keepIf,seq[T],proc(T)>`_,
## Unlike the `keepIf proc<#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 func<#keepIf,seq[T],proc(T)>`_
## * `keepIf proc<#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

func all*[T](s: openArray[T], pred: proc(x: T): bool {.closure.}): bool =
proc 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 func<#any,openArray[T],proc(T)>`_
## * `any proc<#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 func<#all,openArray[T],proc(T)>`_,
## Unlike the `all proc<#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 func<#all,openArray[T],proc(T)>`_
## * `all proc<#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

func any*[T](s: openArray[T], pred: proc(x: T): bool {.closure.}): bool =
proc 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 func<#all,openArray[T],proc(T)>`_
## * `all proc<#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 func<#any,openArray[T],proc(T)>`_,
## Unlike the `any proc<#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 func<#any,openArray[T],proc(T)>`_
## * `any proc<#any,openArray[T],proc(T)>`_
## * `allIt template<#allIt.t,untyped,untyped>`_
##
runnableExamples:
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 func<#map,openArray[T],proc(T)>`_
## * `map proc<#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`` func to reduce typing.
## Convenience template around the mutable ``apply`` proc 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 func<#apply,openArray[T],proc(T)_2>`_
## * `apply proc<#apply,openArray[T],proc(T)_2>`_
## * `mapIt template<#mapIt.t,typed,untyped>`_
##
runnableExamples:
Expand Down

0 comments on commit 9137bd2

Please sign in to comment.