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

allow TextIOWrapper to be enumerated #131

Open
joprice opened this issue Jul 22, 2024 · 0 comments
Open

allow TextIOWrapper to be enumerated #131

joprice opened this issue Jul 22, 2024 · 0 comments

Comments

@joprice
Copy link

joprice commented Jul 22, 2024

Could TextIOWrapper be made to be an enumerable of string? I am able to do this with a cast, which generates a call to get_enumerator that happens to call iter() on the object and work:

use result = builtins.``open`` ("test.txt", OpenTextMode.Read)
for (line: string) in !!result do
  let line = line.Trim()
  builtins.print $"'{line}'"

I can also use readline directly for a typesafe verison, but as a side note, I also noticed that it requires a parameter, where as the parameter should be optional:

use result = builtins.``open`` ("test.txt", OpenTextMode.Read)
let mutable line = result.readline (-1)
line <- line.Trim()
while line <> "" do
  line <- line.Trim()
  builtins.print $"'{line}'"
  line <- result.readline (-1)
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

No branches or pull requests

1 participant