MinMaxState >>
 Latest : Arg
;

C_* :
 MIN
 MAX
;

Max ->
Arg Items : Array | List, Pc : Float,
    Value : < Arg, &Arg >, Store : < Arg, Integer >

Call Enumerate Items . Pc 'State' Value Store CompareMax
With State : MinMaxState = . ..

Return

/* * */

Min ->
Arg Items : Array | List, Pc : Float,
    Value : < Arg, &Arg >, Store : < Arg, Integer >

Call Enumerate Items . Pc 'State' Value Store CompareMin
With State : MinMaxState = . ..

Return

/* * */

CompareMax = Compare ? *, C_MAX
CompareMin = Compare ? *, C_MIN

/* * */

Compare Compare% ->
Arg A : Data, R : ^&Report,
    T : C_MAX | C_MIN

If A.Step = 1 then
 Call Copy A 'R'
Else
 S : MinMaxState = R.Ext.State

 If T = C_MAX then
  If A.Value > S.Latest, A.Precision then Call Copy A 'R'
  Else _
 Else
  If A.Value < S.Latest, A.Precision then Call Copy A 'R'
  Else _
 ;
;

Return

/* * */

Copy Compare ->
Arg A : Data, R : ^&Report

R.Key = A.Key; R.Record = A.Record; R.Step = A.Step
State : MinMaxState = < Latest : A.Value >
R.Ext.State = State

Return