Given the following list
List Records
where Record is
type Record
= RecordA A
| RecordB B
and A and B are type aliases with pos field:
type alias A =
{ pos : Maybe Int
, type : Char
}
how would I create a new list that numbers subsequent A and B records? I want to have pos = 1 in the first A record, pos = 2 in the second A record, pos = 1 in the first B record, etc. (The original list comes without numbers in the pos field.)
This is a solution for a language that allows mutation.
let countA = 0;
let countB = 0;
for (el of my_array) {
el.pos = (el.type == 'A') ? ++countA : ++countB;
}