Iltotore / iron

Strong type constraints for Scala
https://iltotore.github.io/iron/docs/
Apache License 2.0
427 stars 37 forks source link

Support first order types #202

Closed ajaychandran closed 4 months ago

ajaychandran commented 6 months ago

Is there an equivalent of wrapAll operator from zio-prelude?

Describe the solution you'd like

trait RefinedTypeOps[A, C, T]:

  inline def apply[F[*]](v: F[A :| C]): F[T]

  inline def assume[F[*]](v: F[A]): F[T]
Iltotore commented 5 months ago

I'm not sure how using the same name for wrapAll would play with overloading. Also I don't think replacing the old apply/assume with this implementation is a good idea because it would break binary compatibility and probably mess with type inference.

I suggest to use another name like applyF/assumeF or wrapAll.

ajaychandran commented 5 months ago

+1 for applyF/assumeF.

Iltotore commented 5 months ago

After trying to implement it, I don't think it is possible to implement applyF without requiring something like a Monad/ForEach typeclass because wrapAll is not equivalent to applyF. It is similar to assumeF (aka just an alias for asInstanceOf[F[A]]).

ajaychandran commented 5 months ago

I was thinking that applyF would have the same the same implementation (asInstanceOf[F[A]]) but I see now how this can be confusing.

I am fine with just assumeF. Also, it would be nice to have an extension method of the same name.

Iltotore commented 5 months ago

Sounds like a good (and useful) idea to me.