Skip to content

SequencesExt!Fold[Left|Right] over domain of sequence #101

@lemmy

Description

@lemmy

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions