what is the difference between either and Option in dartz?

1.7k views Asked by At

i am trying to understand dartz, but the documentation is not clear enough. i need to get the difference between either and Option in dartz?

abstract class Option<A> implements TraversableMonadPlusOps<Option, A>

VS

abstract class Either<L, R> implements TraversableMonadOps<Either<L, dynamic>, R> 
1

There are 1 answers

0
nvoigt On BEST ANSWER

Well, an Option type normally is a type that holds either a typed value, or nothing.

For example if you want to get the first integer of a list of integers, that might be an Option<int> because it can be an int or nothing in case the list is empty. But it cannot be a string.

An Either type is just what the name says... either one or the other. And it can be two different types altogether. Either<int, string> would have either an int or a string. Never both. Never none. Either one or the other.

For example a functional ParseInt method might return a Either<int, string>, because it will return either a valid int, or an error message.