Skip to content

Commit

Permalink
fix(py): min/max key can be None
Browse files Browse the repository at this point in the history
  • Loading branch information
litlighilit committed Jan 31, 2025
1 parent dc18089 commit c0d5a06
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/pylib/builtins/min_max.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import std/hashes
import std/options

import ../collections_abc
import ../noneType
import ./iter_next
export iter_next.items

Expand Down Expand Up @@ -55,21 +56,22 @@ template cmpByKey[T](dir, key; a, b: T): T =
template gen(sym, dir, symName){.dirty.} =
## min/max(a, b) is alreadly defined by `system`
func sym*[T; R](a, b: T; key: PyLibKey[T, R]): T = cmpByKey(dir, key, a, b)
func sym*[T; R](a, b: T; key: NoneType): T = sym(a, b)

func sym*[T](a, b, c: T; args: varargs[T]): T =
result = sym(sym(a, b), c)
for i in args: result = sym(result, i)


proc sym*[T](it: Iterable[T]): T =
proc sym*[T](it: Iterable[T], key = None): T =
withoutDefaultImpl sym(result, res.unsafeGet), symName

proc sym*[T; R](it: Iterable[T],
key: PyLibKey[T, R]): T =
withoutDefaultImpl cmpByKey(dir, key, result, res.unsafeGet), symName


proc sym*[T](it: Iterable[T]; default: T): T =
proc sym*[T](it: Iterable[T]; default: T, key = None): T =
withDefaultImpl sym(result, i)

proc sym*[T; R](it: Iterable[T]; default: T;
Expand Down

0 comments on commit c0d5a06

Please sign in to comment.