hawk icon indicating copy to clipboard operation
hawk copied to clipboard

Filter command

Open lucabrunox opened this issue 10 years ago • 3 comments

Hawk --apply and --map modes are used to transform the input if I didn't get it wrong. I'd suggest to add a --filter command complementary to --map in order to obtain a filterMap for each element. That is, if the filter does not pass, the line won't be shown. For example: seq 4 | hawk -fd '(&&) <$> ("1" /=) <*> ("3" /=)' would be 2 and 4.

lucabrunox avatar Jan 07 '14 15:01 lucabrunox

That would be probably also writable with hawk -ad 'filter ((&&) <$> ("1" /=) <*> ("3" /=))' though, maybe not worth it. (Still unable to get around the ByteString/String conversion of hawk sorry).

lucabrunox avatar Jan 07 '14 16:01 lucabrunox

For now it is possible to filter like:

> seq 4 | hawk -d -a 'L.filter ((&&) <$> (B.pack "1" /=) <*> (B.pack "3" /=))'
2
4

where B.pack is the pack function of Data.ByteString.Char8.

We are planning to add a new mode called filter as you said. It will work very similar to the map mode.

The String/ByteString problem needs still a lot of work. We use ByteString but the user is expecting String and even with OverloadedStrings we don't get the result that we want.

melrief avatar Jan 07 '14 16:01 melrief

ByteString, String, or even Int! We have a prototype which automatically casts the input to match the type of the user expression, I hope we can fit that into the next version.

gelisam avatar Jan 07 '14 18:01 gelisam