How to convert a tuple of Eithers to a list of Eithers?

  • A+
Category:Languages

I got a tuple with Either values in it,

(Left "Error1", Right 1, Left "Error2", Right 2)  

How can i convert this to

[Left "Error1", Right 1, Left "Error2", Right 2] 

?

Since I want to do lefts on the list and get all Left values from

[Left "Error1", Right 1, Left "Error2", Right 2] 

I have something like this with 38 values in the tuple, (Left "Error1", Right 1, Left "Error2", Right "NameString") is it possible to get only the left values from the tuple?

 


This question has nothing to do with Either – you could as well ask how to convert a tuple of characters into a list of characters.

The answer is: there is no standard method for doing this, but you can just write a lambda / custom function

    /(a,b,c,d) -> [a,b,c,d] 

You should ask yourself the question why you have such a tuple in the first place. Big-ish homogeneous tuples seem fishy; probably you should instead built a list right where it comes from instead.

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: