Call-by-name parameter for `as`
This issue in http4s shows that Functor.as (and all the paths leading there) should evaluate their argument lazily. Maybe... Please evaluate.
https://github.com/http4s/http4s/issues/4971
It's very tricky to explain when "you should use map(_ => x) instead of as(x)".
Yes, this is a frustrating one.
How might we fix it in a compatible fashion? Could we overload it, making the existing one non-implicit and private? Can anyone think of instances that override the default, and if so, exploit its strictness?
How might we fix it in a compatible fashion? Could we overload it, making the existing one non-implicit and private? Can anyone think of instances that override the default, and if so, exploit its strictness?
Overloading works, particularly since we can make the old one protected. We actually had to do that in Cats Effect 3 since we accidentally defined SyncIO#as to be lazy.
The overriding is… more of a problem. I'm not sure if we can fix that, since overloading would take away all of the overridden call sites.
I found no overrides in Cats with GitHub search, but it's worth checking with proper tooling. Even then, there are of course instances outside Cats. Like Sync.