-
Notifications
You must be signed in to change notification settings - Fork 95
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
RestoreTo[F[_], G[_]]
extends Lift[G[_], F[_]]
.
#122
Conversation
private[this] implicit val containsInstanceAny: Contains[Nothing, Any] = | ||
new Contains[Nothing, Any] { | ||
def set(s: Nothing, b: Any): Nothing = s | ||
def extract(s: Nothing): Any = s.asInstanceOf[Any] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
asInstanceOf is redundant
Also, may be this instance should be somewhere in optics module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, but I haven't found more suitable place for such dummy instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think such instance can be abstracted to smth like:
def subtype[A, B >: A]: Contains[A, B] = PContains[A, B](identity)((x, _) => x)
and moved to tofu.optics.functions
.
@Odomontois, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with moving, but I like the current non-allocating version more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I believe such an instance would break Lens laws in general.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, sorry, my mistake.
Counterexample: for Contains[Boolean, Boolean]
such instance, we have: extract(set(true, false)) = true
@@ -78,10 +79,12 @@ object ZioTofuInstance { | |||
} | |||
} | |||
|
|||
class ZioTofuErrorsToInstance[R, E, E1] extends ErrorsTo[ZIO[R, E, *], ZIO[R, E1, *], E] { | |||
class ZioTofuErrorsToInstance[R, E, E1](implicit lens: Contains[E1, E]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks we need only Extract
instance here
def extract(s: Nothing): Any = s | ||
} | ||
|
||
private[this] def zioErrorsToInstanceAny: ZioTofuErrorsToInstance[Any, Any, Nothing] = new ZioTofuErrorsToInstance[Any, Any, Nothing] | ||
final def zioTofuErrorsToInstance[R, E, E1]: ZioTofuErrorsToInstance[R, E, E1] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This instance is not sound anymore.
You can not transform ZIO[R, E1, A]
to ZIO[R, E, A]
without any prior knowledge about how to map E1
to E
I'm afraid trying to cast arbitrary E1
to Nothing
would bring ClassCastException
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose best we can do here is a change E1
to Nothing
explicitly for that instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Odomontois, you mean final def zioTofuErrorsToInstance[R, E]: ZioTofuErrorsToInstance[R, E, Nothing]
?
@@ -78,10 +79,12 @@ object ZioTofuInstance { | |||
} | |||
} | |||
|
|||
class ZioTofuErrorsToInstance[R, E, E1] extends ErrorsTo[ZIO[R, E, *], ZIO[R, E1, *], E] { | |||
class ZioTofuErrorsToInstance[R, E, E1](implicit lens: Extract[E1, E]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So now the only use of the lens
parameter is to Extract
something from Nothing
This is perfectly legit and could not touch performance (since mapError is never applied).
But it looks like we need at least one additional instance , e.g.
final def zioTofuExtractErrorsInstance[R, E, E1: * Extract E1]: ZioTofuErrorsToInstance[R, E, E1] =
new ZioTofuErrorsToInstance
To justify this encoding.
@@ -56,4 +56,6 @@ object functions { | |||
def some[A]: Subset[Option[A], A] = Subset[Option[A]](identity)(Some(_)) | |||
|
|||
def none[A]: Subset[Option[A], Unit] = Subset[Option[A]](_ => Some(()))(_ => None) | |||
|
|||
def extractAnyFromNothing: Extract[Nothing, Any] = (s: Nothing) => s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, Extract[A, B]
unlike Lens[A, B]
is perfectly legal for any A <: B
, so it would be better to see more general case here.
Close #117