Repository navigation
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
|
|
||
| implicit class withSpaceTimeToSpatialMethods[ | ||
| K: SpatialComponent: TemporalComponent, | ||
| K: SpatialComponent: TemporalComponent: λ[α => M[α] => Functor[M, α]]: λ[α => Component[M[α], Bounds[α]]], |
There was a problem hiding this comment.
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.
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.
| new ContextRDD(rdd, metadata) | ||
| } | ||
|
|
||
| implicit class TileLayerMetadataFunctor[A](val self: TileLayerMetadata[A]) extends Functor[TileLayerMetadata, A] { |
There was a problem hiding this comment.
Comments to explain why this is needed.
…/functor-kindprojector
Comments coverage
TODO
FunctortraitTileLayerMetadata[K](maps overKeyBounds)SpatialComponentconstraint onTIleLayerMetadata.apply.mapto 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.toSpatialdoesn't reflect the change in key type in its metadata. After much deliberation, we recognized our attempts to address this as attempts to write aFunctorinstance forTileLayerMetadata[K]which maps over itsKeyBounds. Unfortunately, Scalaz'sFunctortrait 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
Ais lifted intoFunctor's type signature. This allows us to write code like this: