Skip to content

#index is not correct for filter-map sequences #758

@paullgdc

Description

@paullgdc

The #index pointer in filter map sequences is always incremented in map, even though some elements have been skipped.

I believe this is caused by hte filter map optimization pass. Since map(filter(..)) are compiled as a single loop, the #index pointer has the same value in both the filter and the map predicate when they are evaluated.

This means that we get different results if filter maps are directly chained, or if they are done in two steps with variable assignements.

Btw, the explain tab in the playground seems to give the correct results.

Example:

// chained
let a = 0..5 | filter(# %2 == 0) | map(#index);
// not chained
let b_filter = 0..5 | filter(# %2 == 0);
let b_map = b_filter | map(#index);

[a, b_map]

Output

[[0,2,4], [0,1,2]]

Expected output

[[0,1,2], [0,1,2]]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions