# Order Functions

## Optimized for Order

StaticRanges.ordmaxFunction
ordmax(x) = ordmax(x, order(x))
ordmax(x::T, ::Ordering) -> T

Finds the maximum of x using information about its ordering.

source
StaticRanges.ordminFunction
ordmin(x) = ordmin(x, order(x))
ordmin(x::T, ::Ordering) -> T

Finds the minimum of x using information about its ordering.

source
StaticRanges.find_maxFunction
find_max(x)

Returns the index of the maximum value for x. Differes from findmax by accounting for any sorting.

source
StaticRanges.find_minFunction
find_min(x)

Returns the index of the minimum value for x. Differes from findmin by accounting for any sorting.

source
StaticRanges.gtmaxFunction
gtmax(x, y) -> Bool

Returns true if the maximum of x is greater than that of y.

source
StaticRanges.ltmaxFunction
ltmax(x, y) -> Bool

Returns true if the maximum of x is less than that of y.

source
StaticRanges.gtminFunction
gtmin(x, y) -> Bool

Returns true if the minimum of x is greater than that of y.

source
StaticRanges.ltminFunction
ltmin(x, y) -> Bool

Returns true if the minimum of x is less than that of y.

source
StaticRanges.min_of_group_maxFunction
min_of_group_max(x, y)

Returns the minimum of maximum of x and y. Functionally equivalent to min(maximum(x), maximum(y)) but uses trait information about ordering for improved performance.

source
StaticRanges.max_of_group_minFunction
max_of_group_min(x, y)

Returns the maximum of minimum of x and y. Functionally equivalent to max(minimum(x), minimum(y)) but uses trait information about ordering for improved performance.

source

## Order traits

Internally it provides an intermediate structure for chaining functions an arbitrary number of functions.

julia> fxn1 = <(4) | >(8)
(::StaticRanges.ChainedFix{typeof(|),Base.Fix2{typeof(<),Int64},Base.Fix2{typeof(>),Int64}}) (generic function with 3 methods)

julia> fxn2 = <(4) | >(8) & iseven
(::StaticRanges.ChainedFix{typeof(|),Base.Fix2{typeof(<),Int64},StaticRanges.ChainedFix{typeof(&),Base.Fix2{typeof(>),Int64},typeof(iseven)}}) (generic function with 3 methods)

julia> fxn1(10)
true

julia> fxn1(11)
true

julia> fxn2(10)
true

julia> fxn2(11)
false

This becomes particularly useful when trying to preserve a range in a type stable manner. Without knowing the specific functions that compose the conditional operator in findall at compile time it's impossible to determine whether the output should be a continuous range or discrete vector.

julia> findall(i -> >(4)(i) & <(8)(i), fr)
2-element Array{Int64,1}:
3
4

julia> find_all(>(4) & <(8), fr)
3:4
StaticRanges.find_firstFunction
find_first(predicate::Function, A)

Return the index or key of the first element of A for which predicate returns true. Return nothing if there is no such element.

Indices or keys are of the same type as those returned by keys(A) and pairs(A).

Examples

julia> using StaticRanges

julia> A = [1, 4, 2, 2];

julia> find_first(iseven, A)
2

julia> find_first(x -> x>10, A) # returns nothing, but not printed in the REPL

julia> find_first(isequal(4), A)
2

julia> find_first(iseven, [1 4; 2 2])
CartesianIndex(2, 1)
source
StaticRanges.find_lastFunction
find_last(predicate::Function, A)

Return the index or key of the last element of A for which predicate returns true. Return nothing if there is no such element.

Indices or keys are of the same type as those returned by keys(A) and pairs(A).

Examples

julia> using StaticRanges

julia> find_last(iseven, [1, 4, 2, 2])
4

julia> find_last(x -> x>10, [1, 4, 2, 2]) # returns nothing, but not printed in the REPL

julia> find_last(isequal(4), [1, 4, 2, 2])
2

julia> find_last(iseven, [1 4; 2 2])
CartesianIndex(2, 2)
source
StaticRanges.vcat_sortFunction
vcat_sort(x, y)

Returns a sorted concatenation of x and y.

Examples

julia> using StaticRanges

julia> StaticRanges.vcat_sort(1:10)  # it's already sorted, nothing happens
1:10

julia> StaticRanges.vcat_sort([3, 1, 2, 5])  # sort unordered collection
4-element Array{Int64,1}:
1
2
3
5

julia> StaticRanges.vcat_sort([3, 4, 5], [1, 2, 5])
6-element Array{Int64,1}:
1
2
3
4
5
5

source