Skip to content

FlatTraverse can produce type errors #185

@mrdziuban

Description

@mrdziuban

Thank you for these rules, I find them really helpful!

I found that the FlatTraverse rule may rewrite code in a way that produces type errors. For example, this traverses a List[String] and produces an IO[List[Option[Int]]], then maps and flattens it to a List[Int]:

List("", "foo", "bar").traverse(s =>
  IO(Some(s.length).filter(_ > 0))
).map(_.flatten)

When it's rewritten to flatTraverse it triggers a type error since flatTraverse would require the given function to return an IO[List[?]].

I think fixing this would require changing it to a SemanticRule.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions