Delay passing Unzip[A] to Zipper until it is really needed.#1
Delay passing Unzip[A] to Zipper until it is really needed.#1arosien wants to merge 1 commit intostanch:masterfrom
Conversation
This makes it possible to write a `cats.Functor` instance giving us a `map` method. With the `Unzip[A]` passed to the contructor, we can't write `map` without the "target" `Unzip[B]`.
|
Sorry for the delay! I am not familiar with |
|
My real goal is to be able to def map[B](f: A => B)(implicit ub: Unzip[B]): Zipper[B] =
copy(left = left.map(f), focus = f(focus), right = right.map(f), top = top.map(_.map(f))) The issue with |
|
This is interesting, because I believe your Here is the definition of trait Unzip[A] {
def unzip(node: A): List[A]
def zip(node: A, children: List[A]): A
}Upon closer inspection, trait Unzip[A] { self =>
def unzip(node: A): List[A]
def zip(node: A, children: List[A]): A
final def imap[B](f: A => B)(g: B => A) = new Unzip[B] {
def unzip(node: B): List[B] = self.unzip(g(node)).map(f)
def zip(node: B, children: List[B]): B = f(self.zip(g(node), children.map(g)))
}
}So technically I think this makes |
This makes it possible to write a
cats.Functorinstance giving us amapmethod. With theUnzip[A]passed to the contructor, we can't writemapwithout the "target"Unzip[B].