I've encountered situations where I needed to fold (either left or right) over the indices of a sequence. In other words, the operation involves both the current element and its index within the input sequence. Currently, to overcome this limitation, we must resort to folding over a sequence that represents the domain of the original sequence:
FoldLeft(LAMBDA acc, idx:
IF log[idx].something = "foobar" /\ idx < someBound
THEN {log[idx]} \cup acc
ELSE acc,
{}, [ i \in DOMAIN log |-> i])
Preferred:
FoldLeftDomain(LAMBDA acc, idx:
IF log[idx].something = "foobar" /\ idx < someBound
THEN {log[idx]} \cup acc
ELSE acc,
{}, log)
A more elegant, though backward-incompatible, approach could involve increasing the arity of op to include acc, e, and idx:
FoldLeft(LAMBDA acc, e, idx:
IF e.something = "foobar" /\ idx < someBound
THEN {e} \cup acc
ELSE acc,
{}, log)
Thoughts?
I've encountered situations where I needed to fold (either left or right) over the indices of a sequence. In other words, the operation involves both the current element and its index within the input sequence. Currently, to overcome this limitation, we must resort to folding over a sequence that represents the domain of the original sequence:
Preferred:
A more elegant, though backward-incompatible, approach could involve increasing the arity of
opto includeacc,e, andidx:Thoughts?