added generic min;max;each
This commit is contained in:
parent
eb6d77e46d
commit
233687adf7
1 changed files with 17 additions and 0 deletions
|
|
@ -438,6 +438,11 @@ proc min*(x, y: int32): int32 {.magic: "MinI", noSideEffect.}
|
||||||
proc min*(x, y: int64): int64 {.magic: "MinI64", noSideEffect.}
|
proc min*(x, y: int64): int64 {.magic: "MinI64", noSideEffect.}
|
||||||
## The minimum value of two integers.
|
## The minimum value of two integers.
|
||||||
|
|
||||||
|
proc min*[T](x: openarray[T]): T =
|
||||||
|
## The minimum value of an openarray.
|
||||||
|
result = x[0]
|
||||||
|
for i in 1..high(x): result = min(result, x[i])
|
||||||
|
|
||||||
proc max*(x, y: int): int {.magic: "MaxI", noSideEffect.}
|
proc max*(x, y: int): int {.magic: "MaxI", noSideEffect.}
|
||||||
proc max*(x, y: int8): int8 {.magic: "MaxI", noSideEffect.}
|
proc max*(x, y: int8): int8 {.magic: "MaxI", noSideEffect.}
|
||||||
proc max*(x, y: int16): int16 {.magic: "MaxI", noSideEffect.}
|
proc max*(x, y: int16): int16 {.magic: "MaxI", noSideEffect.}
|
||||||
|
|
@ -445,6 +450,11 @@ proc max*(x, y: int32): int32 {.magic: "MaxI", noSideEffect.}
|
||||||
proc max*(x, y: int64): int64 {.magic: "MaxI64", noSideEffect.}
|
proc max*(x, y: int64): int64 {.magic: "MaxI64", noSideEffect.}
|
||||||
## The maximum value of two integers.
|
## The maximum value of two integers.
|
||||||
|
|
||||||
|
proc max*[T](x: openarray[T]): T =
|
||||||
|
## The maximum value of an openarray.
|
||||||
|
result = x[0]
|
||||||
|
for i in 1..high(x): result = max(result, x[i])
|
||||||
|
|
||||||
proc `+%` *(x, y: int): int {.magic: "AddU", noSideEffect.}
|
proc `+%` *(x, y: int): int {.magic: "AddU", noSideEffect.}
|
||||||
proc `+%` *(x, y: int8): int8 {.magic: "AddU", noSideEffect.}
|
proc `+%` *(x, y: int8): int8 {.magic: "AddU", noSideEffect.}
|
||||||
proc `+%` *(x, y: int16): int16 {.magic: "AddU", noSideEffect.}
|
proc `+%` *(x, y: int16): int16 {.magic: "AddU", noSideEffect.}
|
||||||
|
|
@ -1102,6 +1112,13 @@ proc pop*[T](s: var seq[T]): T {.inline.} =
|
||||||
result = s[L]
|
result = s[L]
|
||||||
setLen(s, L)
|
setLen(s, L)
|
||||||
|
|
||||||
|
proc each*[T, S](data: openArray[T], op: proc (x: T): S): seq[S] =
|
||||||
|
## The well-known ``map`` operation from functional programming. Applies
|
||||||
|
## `op` to every item in `data` and returns the result as a sequence.
|
||||||
|
result = @[]
|
||||||
|
for d in items(data): add(result, op(d))
|
||||||
|
|
||||||
|
|
||||||
# ----------------- FPU ------------------------------------------------------
|
# ----------------- FPU ------------------------------------------------------
|
||||||
|
|
||||||
#proc disableFPUExceptions*()
|
#proc disableFPUExceptions*()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue