A common problem I got in Haskell is to extract all terms in a list belonging to a specific data constructor and I'm wondering if there are any better ways than the way I'm doing it at the moment.
Let's say you got
data Foo = Bar | Goo
, the list
foos = [Bar, Goo, Bar, Bar, Goo]
and wish to extract all Goo
s from foos
. At the moment I usually do something like
goos = [Goo | Goo <- foos]
and all is well. The problem is when Goo
got a bunch of fields and I'm forced to write something like
goos = [Goo a b c d e f | Goo a b c d e f <- foos]
which is far from ideal. How you do usually handle this problem?