Skip to content
This repository was archived by the owner on Dec 22, 2021. It is now read-only.
This repository was archived by the owner on Dec 22, 2021. It is now read-only.

Improve usability of lengthCompare #338

@joroKr21

Description

@joroKr21

In most codebases I've seen people just use seq.length/size <> n even though seq.lengthCompare(n) <> 0 is recommended for sequential collections. In some cases it's probably for lack of knowledge, but in others the latter is just deemed too unreadable.

My suggestion is to add some shortcuts that make it more pleasant to use.
Something along those lines:

def lengthEq(n: Int):  Boolean = lengthCompare(n) == 0
def lengthMin(n: Int): Boolean = lengthCompare(n) >= 0
def lengthMax(n: Int): Boolean = lengthCompare(n) <= 0

Other suggestions also welcome, of course.

This particular issue came up on Gitter.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions