Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid redundant toList-calls in containers package #1570

Open
jvoigtlaender opened this issue Feb 5, 2024 · 1 comment
Open

avoid redundant toList-calls in containers package #1570

jvoigtlaender opened this issue Feb 5, 2024 · 1 comment

Comments

@jvoigtlaender
Copy link
Contributor

In the spirit of #1569, various toList calls could be optimized away. But I'm not sure containers is "in scope" since no other rules currently seem to refer to functions from it.

Anyway, here are the proposed rules:

    - warn: {lhs: foldMap f (Data.IntMap.toList x), rhs: Data.IntMap.foldMapWithKey (curry f) x}
    - warn: {lhs: foldr f z (Data.IntMap.toList x), rhs: Data.IntMap.foldrWithKey (curry f) z x}
    - warn: {lhs: foldr' f z (Data.IntMap.toList x), rhs: Data.IntMap.foldrWithKey' (curry f) z x}
    - warn: {lhs: foldl f z (Data.IntMap.toList x), rhs: Data.IntMap.foldlWithKey (curry . f) z x}
    - warn: {lhs: foldl' f z (Data.IntMap.toList x), rhs: Data.IntMap.foldlWithKey' (curry . f) z x}
    - warn: {lhs: null (Data.IntMap.toList x), rhs: Data.IntMap.null x}
    - warn: {lhs: length (Data.IntMap.toList x), rhs: Data.IntMap.size x}

    - warn: {lhs: foldr f z (Data.IntSet.toList x), rhs: Data.IntSet.foldr f z x}
    - warn: {lhs: foldr' f z (Data.IntSet.toList x), rhs: Data.IntSet.foldr' f z x}
    - warn: {lhs: foldl f z (Data.IntSet.toList x), rhs: Data.IntSet.foldl f z x}
    - warn: {lhs: foldl' f z (Data.IntSet.toList x), rhs: Data.IntSet.foldl' f z x}
    - warn: {lhs: null (Data.IntSet.toList x), rhs: Data.IntSet.null x}
    - warn: {lhs: length (Data.IntSet.toList x), rhs: Data.IntSet.size x}
    - warn: {lhs: elem y (Data.IntSet.toList x), rhs: Data.IntSet.member y x}
    - warn: {lhs: notElem y (Data.IntSet.toList x), rhs: Data.IntSet.notMember y x}

    - warn: {lhs: foldMap f (Data.Map.toList x), rhs: Data.Map.foldMapWithKey (curry f) x}
    - warn: {lhs: foldr f z (Data.Map.toList x), rhs: Data.Map.foldrWithKey (curry f) z x}
    - warn: {lhs: foldr' f z (Data.Map.toList x), rhs: Data.Map.foldrWithKey' (curry f) z x}
    - warn: {lhs: foldl f z (Data.Map.toList x), rhs: Data.Map.foldlWithKey (curry . f) z x}
    - warn: {lhs: foldl' f z (Data.Map.toList x), rhs: Data.Map.foldlWithKey' (curry . f) z x}
    - warn: {lhs: null (Data.Map.toList x), rhs: Data.Map.null x}
    - warn: {lhs: length (Data.Map.toList x), rhs: Data.Map.size x}

Similar optimizations would likely also be possible regarding toList from the aeson, vector and unordered-containers packages.

@jvoigtlaender
Copy link
Contributor Author

See also #1620 for more hints that could be added here as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant