Skip to content

allow TextIOWrapper to be enumerated #131

@joprice

Description

@joprice

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions