Skip to content

Seq sort evaluated immediately. Is this Intended behavior? #1181

Closed
@cmschuetz

Description

@cmschuetz

What happened

Calling sort on a Seq evaluated the Seq immediately even though I expect it to not evaluate until the Seq is actually used.

How to reproduce

When I run:

Seq([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]).filter(x => {
  console.log('filtering');
  return x >= 5;
});

I see no output, which is expected behavior. However, when I append a .sort() after the filter call:

Seq([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]).filter(x => {
  console.log('filtering');
  return x >= 5;
}).sort();

I receive the following output:

filtering
filtering
filtering
filtering
filtering
filtering
filtering
filtering
filtering
filtering

Is this intended behavior? If so, do you have any suggestions for combining sort functions with lazy evaluation?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions