MinMaxState >>
 Latest : Arg
;

C_* :
 MIN
 MAX
;

/* * */

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

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

/

/* * */

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

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

/

/* * */

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

/* * */

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

Copy = 0 ..

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

 If T = C_MAX then
  If A.Value > S.Latest .A.Precision then Copy = 1
  Else _
 Else
  If A.Value < S.Latest .A.Precision then Copy = 1
  Else _
 ;
;

If Copy then 
 - Copy 'R' A
;

/

/* * */

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

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

/