Open lucabrunox opened 10 years ago
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).
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.
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.
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.