To expand on what @Ingo was getting: it would be more idiomatic for Haskell to write:
jobField :: (String, String, String) -> String jobField (_, _, j) = j withJob :: [(String, String, String)] -> String -> [(String, String, String)] withJob xs job = filter (\x -> jobField x == job) xs
We can go further:
data Person = Person { pName :: String, pAge :: Int, pJob :: String } filterbyJob :: String -> [Person] -> [Person] filterbyJob job xs = filter (\p -> pJob p == job) xs
And even then:
filterbyJob :: String -> [Person] -> [Person] filterbyJob job = filter (\p -> pJob p == job)
Or even:
filterbyJob :: String -> [Person] -> [Person] filterbyJob job = filter ((== job) . pJob)
At this point, if no one will use filterByJob horribly, it probably does not provide real value, except to just write filter ((== job) . pJob) where you need it!
The point of this exercise is that there is a powerful filter function that you can simply use rather than rewrite this code each time. This not only saves you time and code, but by reusing the well-known feature, you will make it easier for future programmers to understand the code (including your future!)
source share