How to use a lamdba with Either in a map function?

82 Views Asked by At

What I try to do is the following:

map ((\Left x -> x + 1) [1, 2]

... and I would expect it to return

[2, 3]

However, I get the following error:

<interactive>:25:14: error: parse error on input ‘)’ 

What am I doing wrong here?

1

There are 1 best solutions below

0
Louis Wasserman On

You have incorrectly organized your parentheses, and introduced Either when it's not related to any of the other code.

Write

map (\ x -> x + 1) [1, 2]

It's not clear why you want Either to be involved, since you're mapping over a list without any Either values in it. Maybe what you want is

map (\ (Left x) -> x + 1) [Left 1, Left 2]