-
Notifications
You must be signed in to change notification settings - Fork 360
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
Custom Functor Typeclass #1643
Custom Functor Typeclass #1643
Conversation
This may or may not be an actual Functor, depending on how well we can convince ourselves that the second Functor law holds: fmap (g . h) = (fmap g) . (fmap h) If you only had one implicit val m: F[A] = ???
val f: A => B = ???
val g: B => C = ???
val n: F[C] = m.map(f).map(g) wouldn't compile. But if you did have both val n: F[C] = m.map(k => g(f(k))) and so the Functor law holds, and it is indeed a Functor. |
Use kind projector lambdas to get rid of explicit implicits usage
@@ -16,9 +16,8 @@ trait Implicits { | |||
extends TileLayerRDDFilterMethods[K, V, M] | |||
|
|||
implicit class withSpaceTimeToSpatialMethods[ | |||
K: SpatialComponent: TemporalComponent, | |||
K: SpatialComponent: TemporalComponent: λ[α => M[α] => Functor[M, α]]: λ[α => Component[M[α], Bounds[α]]], |
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 should be type aliased w/ a broken down explained in a comment, pretty tough to parse and also understand why they just can't be context bounds on M
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's definitely space voodoo the first time you see it, yeah. For technical reasons they can't be bounds on M, so I'll explain that.
@@ -62,6 +61,14 @@ package object spark | |||
new ContextRDD(rdd, metadata) | |||
} | |||
|
|||
implicit class TileLayerMetadataFunctor[A](val self: TileLayerMetadata[A]) extends Functor[TileLayerMetadata, A] { |
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.
Comments to explain why this is needed.
…/functor-kindprojector
Comments coverage
TODO
Functor
traitTileLayerMetadata[K]
(maps overKeyBounds
)SpatialComponent
constraint onTIleLayerMetadata.apply
.map
to inject properly (thanks to @pomadchin )Add test to confirm The toSpatial Method gives metadata of type TileLayerMetadata[SpaceTimeKey] #1575 fix(no point, the compiler guarantees it)Motivation
#1575 describes how
TileLayerRDD.toSpatial
doesn't reflect the change in key type in its metadata. After much deliberation, we recognized our attempts to address this as attempts to write aFunctor
instance forTileLayerMetadata[K]
which maps over itsKeyBounds
. Unfortunately, Scalaz'sFunctor
trait is a bit too restrictive, in that types that use it can't impose additional constraints on their inner type. Compare Scalaz:to our implementation:
where
A
is lifted intoFunctor
's type signature. This allows us to write code like this: