0

I want a function Int -> [[String]], trying to filter out the elements that have a specific value on the Inth spot. I thought I could combine filter and !! but I can't get it to work. So far I have:

filter (!! (== value)) rows

where value is a String and rows is a [[String]]. I thought it would take the Int combined with a [String] from rows and check if that particular entry equals value and then keep those rows, but it gets interpreted differently. Any help would be appreciated.

3
  • You say the Int – but with Int? Commented Sep 20, 2015 at 12:32
  • I'm not sure I understand your question Commented Sep 20, 2015 at 12:34
  • It's often best to start by using explicit lambdas to make sure every function and operator is fully applied, then, if you wish, working to remove them one at a time. Commented Sep 20, 2015 at 18:12

1 Answer 1

3

(!! (== value)) is invalid because the right operand of !! must be an Int. (== value) is a function.

Your options are

\n -> filter (\xs -> xs !! n == value) rows

or without the explicit lambda

\n -> filter ((== value) . (!! n)) rows
Sign up to request clarification or add additional context in comments.

2 Comments

This works indeed. Glad to see my idea was correct, but it was my formulation that was lacking.
@tbpotn I would recommend reading up on pointfree style, to avoid future problems such as this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.