Skip to content

Comments

Custom pipes#28

Open
stevana wants to merge 4 commits intojgm:masterfrom
stevana:custom-pipes-io
Open

Custom pipes#28
stevana wants to merge 4 commits intojgm:masterfrom
stevana:custom-pipes-io

Conversation

@stevana
Copy link

@stevana stevana commented Nov 21, 2023

I also needed custom pipes and saw #11 with the comment:

Seems like there's a lot of interest in this. Is anyone interested in making a PR so we could consider it more concretely?

So I thought I'd give it a try.

Previously we had `foldr applyPipe (reverse pipes)`, with monadic
pipes we had to change the `foldr` to `foldM` and so we should no
longer reverse the list as witnessed by the following repl session:

    > foldr (\x ih -> traceShow x x + ih) 0 (reverse [1,2,3])
    1
    2
    3
    6

    > foldM (\ih x -> print x >> return (x + ih)) 0 [1,2,3]
    1
    2
    3
    6

This makes all tests pass again.
@jgm
Copy link
Owner

jgm commented Nov 26, 2023

Why monadic and not just a pure function? A pure function would handle the cases mentioned in #11.

Also, what's the intended use of the text arguments? Example?

@stevana
Copy link
Author

stevana commented Nov 27, 2023

Why monadic and not just a pure function?

I found myself wanting to do $data.url/download$ which does a http request to download the source of some url.

Also, what's the intended use of the text arguments? Example?

There's an example in the tests, $text/replace "foo" "bar"$, which searches through the text and replaces all foo with bar.

(I realised after I made this PR that I actually needed input data dependent arguments, i.e. $data.url/download data.title$. This seemed a lot more involved to implement, so I started looking at other ways of doing it than using doctemplates.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants