Skip to content

Option.fold and Either.fold have inconsistent parameter lists (and Option.fold has worse type inference) #10642

@SethTisue

Description

@SethTisue

Either#fold has one parameter list,def fold[C](fa: A => C, fb: B => C): C

but Option#fold has two, def fold[B](ifEmpty: => B)(f: A => B): B

as shown in #9262, the single-parameter-list version offers better type inference

it's also simply confusing that the two are different

fwiw, the difference goes away in Dotty, which can infer the right type either way:

scala> Option(5).fold(Left("err"))(Right(_)) 
val res0: scala.util.Either[String, Int] = Right(5)

given that the improvement in type inference is coming in Dotty, it might still be worth bringing the two in line for consistency's sake? I fear it's not worth breaking existing code

reported by @Jacoby6000 on #scala IRC

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