Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filtering composite structures with Lens

Tags:

haskell

lenses

I have a [(a, Maybe b)], and want to obtain a [(a, b)], with all pairs where the second element was Nothing filtered out. Is there a concise way to describe this operation using lens?

like image 966
Narvius Avatar asked Oct 25 '13 14:10

Narvius


1 Answers

Notwithstanding the ingeniousity of the Lenses, the follwoing would probably be the mark for conciseness:

[ (a, b) | (a, Just b) <- list ]

(Not to speak of readability.)

like image 66
Ingo Avatar answered Oct 07 '22 01:10

Ingo