diff --git a/lib/pure/algorithm.nim b/lib/pure/algorithm.nim index c9f7790186..bfc2e03510 100644 --- a/lib/pure/algorithm.nim +++ b/lib/pure/algorithm.nim @@ -237,6 +237,19 @@ template sortedByIt*(seq1, op: expr): expr = result = cmp(a, b)) result +proc isSorted*[T](a: openarray[T], + cmp: proc(x, y: T): int {.closure.}, + order = SortOrder.Ascending): bool = + ## Tests whether `a` is sorted + if len(a) <= 1: return true # empty or one-element lists are already sorted + + result = true + for i in 0..