File-like option where the "file contents" comes from a string?

monkyyy crazymonkyyy at gmail.com
Wed Nov 27 20:38:22 UTC 2024


On Wednesday, 27 November 2024 at 14:37:03 UTC, Andy Valencia 
wrote:
> With my OO programming goggles on, I can't help but notice that 
> if Phobos had made File a class--or an interface--

oo doesn't own polymorphism you could do 99% of the value with

```d
struct dummyfile{
   auto byLineCopy()=>//string.spiltter('\n')....
}

auto myfunc(F)(F file){
   foreach(s;file.byLineCopy){
     ...
   }
}
unittest{ assert(
   dummyfile(q{
     ...
   }).myfunc
   == ...);
}
```


More information about the Digitalmars-d-learn mailing list