def PipeSession.end.go

bend-pipe-session@0.2.0.0 · impl.bend:210

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

210def PipeSession.end.go(
211  fuel: Nat,
212  read: File & Result<&1, &1, U32 & String, Maybe<String>>,
213  +line_cap: U32,
214  said: List<&2, String>
215) -> IO(Result<&1, &1, U32 & String, List<&2, String>>):
216  match fuel read:
217    case 0n Tuple{out, _}:
218      do IO<Result<&1, &1, U32 & String, List<&2, String>>>:
219        File.close(out)
220        return Fail{(5, "the program said too many lines after its input ended")}
221    case 1n+rest Tuple{out, Fail{error}}:
222      do IO<Result<&1, &1, U32 & String, List<&2, String>>>:
223        File.close(out)
224        return Fail{error}
225    case 1n+rest Tuple{out, Done{None{}}}:
226      do IO<Result<&1, &1, U32 & String, List<&2, String>>>:
227        File.close(out)
228        return Done{List.reverse(&2, String, said)}
229    case 1n+rest Tuple{out, Done{Some{line}}}:
230      do IO<Result<&1, &1, U32 & String, List<&2, String>>>:
231        next: File & Result<&1, &1, U32 & String, Maybe<String>> <- Stdio.read_line(out, line_cap)
232        PipeSession.end.go(rest, next, line_cap, String.trim_end(line) <> said)

Uses (17)

Used by (1)