DEV Community

loading...

Discussion on: Daily Challenge #172 - Find All in an Array

Collapse
avalander profile image
Avalander

Haskell

Written on the phone, it might not work, I'll check it when I get home.

find_all :: [Int] -> Int -> [Int]
find_all xs n =
  [ snd x | x <- indexed if (fst x) == n ]
  where
    indexed = zip xs [0..(length xs)]
Collapse
citizen428 profile image
Michael Kohl

I find it slightly more idiomatic to write indexed with an infinite list as second argument, since zip will only consume length xs elements from the second list anyway:

indexed = zip xs [0..]