def PipeSession.ask.go
bend-pipe-session@0.2.0.0 · impl.bend:62
import bend-pipe-session@0.2.0.0/impl.bend as Impl
import Base
import bend-stdio-pipes@0.2.0.0/impl.bend as Stdio
62
63def PipeSession.ask.go(
64 fuel: Nat,
65 at: File & Heard,
66 +until: String,
67 +line_cap: U32,
68 said: List<&2, String>
69) -> IO(File & Result<&1, &1, U32 & String, List<&2, String>>):
70 match fuel:
71 case 0n:
72 match at:
73 case (out, _):
74 IO.pure(
75 File & Result<&1, &1, U32 & String, List<&2, String>>,
76 (out, Fail{(5, "the program said too many lines before " ++ until)})
77 )
78 case 1n+rest:
79 match at:
80 case (out, Failed{error}):
81 IO.pure(File & Result<&1, &1, U32 & String, List<&2, String>>, (out, Fail{error}))
82 case (out, Ended{}):
83 IO.pure(
84 File & Result<&1, &1, U32 & String, List<&2, String>>,
85 (out, Fail{(PipeSession.ended(), "the program ended before it said " ++ until)})
86 )
87 case (out, Last{text}):
88 IO.pure(
89 File & Result<&1, &1, U32 & String, List<&2, String>>,
90 (out, Done{List.reverse(&2, String, text <> said)})
91 )
92 case (out, Line{text}):
93 do IO<File & Result<&1, &1, U32 & String, List<&2, String>>>:
94 read: File
95 & Result<&1, &1, U32 & String, Maybe<String>> <- Stdio.read_line(out, line_cap)
96 PipeSession.ask.go(rest, Heard.read(read, until), until, line_cap, text <> said)