Questions tagged [either]

4 questions
24
votes
3 answers

Why use Either over (checked) Exception?

Not too long ago I started using Scala instead of Java. Part of the "conversion" process between the languages for me was learning to use Eithers instead of (checked) Exceptions. I've been coding this way for a while, but recently I started…
Eyal Roth
  • 603
  • 5
  • 11
7
votes
1 answer

Why are Scala's Either and Option types not interfaces/traits but classes?

I wanted to create a class CompileResult, that can be treated like an Either type but has some additional useful methods. It should be a CompileSuccess or a CompileFailure (which, too, has some extended functionality). However I can't do that…
valenterry
  • 2,429
  • 16
  • 21
5
votes
1 answer

Advantages and drawbacks of different ways using Either-types

I am writing software for compiling programs. Therefore have a Compiler that compiles a given sourcecode. It then returns a CompileResult that is similiar to an Either type (it is actually internally delegating to an Either object). Now there can be…
valenterry
  • 2,429
  • 16
  • 21
4
votes
2 answers

Transform Either types in Scala

I have an Either type e.g. Either[A, B] but I want an Either[X, Y] by using two functions A => X and B => Y. I can do that with fold: val myEither: Either[A, B] = ... myEither.fold( a => Left(createNewX()), b => Right(createNewY()) ) But that…
valenterry
  • 2,429
  • 16
  • 21