[Haskell-beginners] reverse 'lookup'
Yitzchak Gale
gale at sefer.org
Wed Jul 7 13:54:48 EDT 2010
Patrick LeBoutillier wrote:
> is there... perhaps a builtin function to flip a pair:
> (a, b) -> (b, a)
The function
swap (x, y) = (y, x)
will be added to Data.Tuple in the next release
of the base libraries. In the meantime, it is easy
enough to define it yourself, and then, of course
rlookup x = lookup x . map swap
Or, you could use the find function from Data.List
and write:
rlookup x = find ((== x) . snd)
Regards,
Yitz
More information about the Beginners
mailing list