Stream: beginners

Topic: Reading Stdin until EOT?


view this post on Zulip Taylor Troesh (Sep 29 2023 at 00:27):

How would I read from Stdin until EOT? I'm trying to pipe input into a basic-cli app and it crashes.

thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value', src/lib.rs:298:45
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
fatal runtime error: failed to initiate panic, error 5

This is my best attempt:

            loop : Str -> Task [Step Str, Done Str] never
            loop = \a -> Task.attempt Stdin.line \x -> when x is
                Ok b -> Task.succeed (Step (Str.concat a b))
                Err _ -> Task.succeed (Done a)
            stdin <- await (Task.loop "" loop)

view this post on Zulip Brendan Hansknecht (Sep 29 2023 at 00:38):

I think this is a case where we need to change how the stdin function works on the platform

view this post on Zulip Brendan Hansknecht (Sep 29 2023 at 00:38):

I think we currently have it just unwrap the stdin option when it really should return an option in the function

view this post on Zulip Brendan Hansknecht (Sep 29 2023 at 00:38):

That way you know when you hit eof instead of crashing

view this post on Zulip Brendan Hansknecht (Sep 29 2023 at 00:39):

Basically, we have a bad default currently that crashes on any error and eof is being considered an error.

view this post on Zulip Brendan Hansknecht (Sep 29 2023 at 00:39):

This would probably be a good first issue for anyone interested.

view this post on Zulip Anton (Sep 29 2023 at 08:57):

Should we change the type of Stdin.line to Task [Input Str, End] *?

view this post on Zulip Isaac Van Doren (Oct 30 2023 at 00:52):

Should we change the type of Stdin.line to Task [Input Str, End] *?

I like the sound of that

view this post on Zulip Brendan Hansknecht (Oct 30 2023 at 01:20):

Should Eof be a normal state or an error state? I would assume it is a error that you normally match on/react to, but I guess either is valid

view this post on Zulip Brendan Hansknecht (Oct 30 2023 at 01:20):

Hmm...in rust, I guess it is result option str

view this post on Zulip Brendan Hansknecht (Oct 30 2023 at 01:21):

So eof is part of the positive side, not error side

view this post on Zulip Isaac Van Doren (Oct 30 2023 at 01:40):

Yeah I don't think it makes sense for eof to be considered an error

view this post on Zulip Isaac Van Doren (Oct 30 2023 at 03:24):

I have this implemented, just need to make sure everything is right and then I'll open up a PR another day


Last updated: Jul 06 2025 at 12:14 UTC