Hacker News new | ask | show | jobs
by mifrai 4922 days ago
Honestly, I don't think danidiaz was trying to be clever so much as not knowing about the existence of filterM. A good chunk of the code was just an implementation of it:

    filterM' f xs = map fst . filter snd . zip xs <$> mapM f xs
So, given filterM, the code would have looked like

    nexist n xs = take n <$> filterM (fmap not . doesFileExist) xs
Which doesn't look clever at all and it's fairly easy to understand.
2 comments

Yeah, I had forgotten about filterM.

By the way, I like the (fmap not . doesFileExist) bit. It´s cleaner and less cluttered than (\f -> doesFileExist f >>= return . not)

Cool, thanks!