You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi everyone. I am having troubles using this trait:
traitDataCache[F[_]] {
deflookup[I, A](i: I, data: Data[I, A]):F[Option[A]]
definsert[I, A](i: I, v: A, data: Data[I, A]):F[DataCache[F]]
}
I want to use it with some underlying Cache[F[_], K:Hash, V] where K is my key and have implementation of cats' Hash. The problem is i can't do something like this:
classMyFetchCache[F[_], K:Hash, V](underlying: Cache[F, K, V]) extendsDataCache[F] {
deflookup[I, A](i: I, data: Data[I, A]):F[Option[A]] = underlying.put(i) // need to castdefinsert[I, A](i: I, v: A, data: Data[I, A]):F[DataCache[F]] = underlying.put(i, v) // need to cast
}
classMyFetchCache[F[_], K, V](underlying: Cache[F, K, V]) extendsDataCache[F] {
deflookup[I:Hash, A](i: I, data: Data[I, A]):F[Option[A]] = underlying.get(i) // doesn't apply to interfacedefinsert[I:Hash, A](i: I, v: A, data: Data[I, A]):F[DataCache[F]] = underlying.put(i, v) // doesn't apply to interface
}
I believe that my best option is to do something like this:
Hello, can you please share the exact compiler messages you are getting when trying to implement this? I'm having trouble seeing the source of the issue. The third block of code won't work as you can't change the interface, so that makes sense, but what is your return value from calling underlying.get/put? If the result value isn't the same, then yes you'll want to do some conversion or wrapping perhaps, depending on the type. Your second example should be a good starting point.
Hi everyone. I am having troubles using this trait:
I want to use it with some underlying
Cache[F[_], K:Hash, V]
where K is my key and have implementation of cats' Hash. The problem is i can't do something like this:I believe that my best option is to do something like this:
And even like this it seems that i'll need a lot of
asInstanceOf
casts.The text was updated successfully, but these errors were encountered: