Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should IO ports be first class? #1880

Open
1 task done
tesujimath opened this issue Jan 10, 2025 · 1 comment
Open
1 task done

Should IO ports be first class? #1880

tesujimath opened this issue Jan 10, 2025 · 1 comment

Comments

@tesujimath
Copy link

What new feature should Elvish have?

I am wondering whether IO ports should be first class, so they could be assigned to variables, passed to functions, etc.

My use-case motivating this is processing stream input, where there is a header to be processed first. So I envisage being able to do from-lines | take 1 for the header, but still subsequently have access to the IO port to read the rest of the stream.

I haven't thought at all about syntax yet, it's the concept I would first like to understand.

This would seem to be an answer also for #741

Thoughts?

Output of "elvish -version"

0.21.0

Code of Conduct

@tesujimath
Copy link
Author

Here's a bit more about what this could look like.

Let's suppose we have a new builtin function make-io-port. And here, obviously, echo is standing in for an external program.

var p = (make-io-port)
echo "1\n2\n3\n4\n5" | from-lines | $p
$p | take 2
▶ 1
▶ 2
$p | take 1
▶ 3
$p
▶ 4
▶ 5

Perhaps we could also or instead have a builtin function capture, which creates an IO port and attaches its input.

var p = (echo "1\n2\n3\n4\n5" | from-lines | capture)
$p | take 2
▶ 1
▶ 2
$p | take 1
▶ 3
$p
▶ 4
▶ 5

This should work for streaming input, so imagine instead of 5 lines, an unending stream from some external source.

I hope that gives the flavour of what I am envisaging. I am sure there is an interesting design space for such a feature!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ❓Triage
Development

No branches or pull requests

1 participant