Turtle library : grepping on Text vs FilePath

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Turtle library : grepping on Text vs FilePath

Ruben Astudillo
Dear list

On the Turtle library, the grep function got the following signature

    grep :: Pattern a -> Shell Line -> Shell Line

For it to filter output of the `ls :: FilePath -> Shell FilePath` I got
to fmap and transform via de Turtle.Format or Turtle.Line modules. Is
this an indicator I shouldn't be doing this? Is the library telling me
to use `find`? or is just accidental?

--
-- Ruben


_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.

signature.asc (499 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Turtle library : grepping on Text vs FilePath

Joe Hillenbrand
Is onFiles[1] what you're looking for?

https://hackage.haskell.org/package/turtle-1.3.5/docs/Turtle-Prelude.html#v:onFiles

On Tue, Jun 6, 2017 at 10:16 PM, Ruben Astudillo <[hidden email]> wrote:

> Dear list
>
> On the Turtle library, the grep function got the following signature
>
>     grep :: Pattern a -> Shell Line -> Shell Line
>
> For it to filter output of the `ls :: FilePath -> Shell FilePath` I got
> to fmap and transform via de Turtle.Format or Turtle.Line modules. Is
> this an indicator I shouldn't be doing this? Is the library telling me
> to use `find`? or is just accidental?
>
> --
> -- Ruben
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|

Re: Turtle library : grepping on Text vs FilePath

Ruben Astudillo
On 07/06/17 03:08, Joe Hillenbrand wrote:
> Is onFiles[1] what you're looking for?
>
> https://hackage.haskell.org/package/turtle-1.3.5/docs/Turtle-Prelude.html#v:onFiles

Almost. Grep operates over Shell Line. Line is just a newtype over Text.
I still don't know if this is telling me "don't do that".

> On Tue, Jun 6, 2017 at 10:16 PM, Ruben Astudillo <[hidden email]> wrote:
>> Dear list
>>
>> On the Turtle library, the grep function got the following signature
>>
>>     grep :: Pattern a -> Shell Line -> Shell Line
>>
>> For it to filter output of the `ls :: FilePath -> Shell FilePath` I got
>> to fmap and transform via de Turtle.Format or Turtle.Line modules. Is
>> this an indicator I shouldn't be doing this? Is the library telling me
>> to use `find`? or is just accidental?
>>
>> --
>> -- Ruben
>>
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> To (un)subscribe, modify options or view archives go to:
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>> Only members subscribed via the mailman list are allowed to post.

--
-- Ruben


_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.

signature.asc (499 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Turtle library : grepping on Text vs FilePath

Joe Hillenbrand
Line is not just a wrapper around Text. It's a guarantee that the
string does not contain any newline characters.

Can you be more explicit about what you are trying to do? I'm having
troubling understanding what you want. Are you trying to filter the
output of `ls` using `grep`?

For that you can do this:

main = do
  view $ grep (suffix "hs") $ fmap (unsafeTextToLine . format fp) (ls ".")

This will print all the files in the current directory that end in "hs".

On Wed, Jun 7, 2017 at 12:22 AM, Ruben Astudillo <[hidden email]> wrote:

> On 07/06/17 03:08, Joe Hillenbrand wrote:
>> Is onFiles[1] what you're looking for?
>>
>> https://hackage.haskell.org/package/turtle-1.3.5/docs/Turtle-Prelude.html#v:onFiles
>
> Almost. Grep operates over Shell Line. Line is just a newtype over Text.
> I still don't know if this is telling me "don't do that".
>
>> On Tue, Jun 6, 2017 at 10:16 PM, Ruben Astudillo <[hidden email]> wrote:
>>> Dear list
>>>
>>> On the Turtle library, the grep function got the following signature
>>>
>>>     grep :: Pattern a -> Shell Line -> Shell Line
>>>
>>> For it to filter output of the `ls :: FilePath -> Shell FilePath` I got
>>> to fmap and transform via de Turtle.Format or Turtle.Line modules. Is
>>> this an indicator I shouldn't be doing this? Is the library telling me
>>> to use `find`? or is just accidental?
>>>
>>> --
>>> -- Ruben
>>>
>>>
>>> _______________________________________________
>>> Haskell-Cafe mailing list
>>> To (un)subscribe, modify options or view archives go to:
>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>>> Only members subscribed via the mailman list are allowed to post.
>
>
> --
> -- Ruben
>
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.