Skip to content

Instantly share code, notes, and snippets.

@julien-truffaut
Created August 23, 2019 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julien-truffaut/bdd1e607a0504b33b91ff79787729b66 to your computer and use it in GitHub Desktop.
Save julien-truffaut/bdd1e607a0504b33b91ff79787729b66 to your computer and use it in GitHub Desktop.
trait Example {
import cats.implicits._
import cats.~>
type VdomNode
type StateSnapshot[A]
type Lens[S, A]
type Layout1 = VdomNode => VdomNode
type Layout2 = (VdomNode, VdomNode) => VdomNode
def render1[A, Z](layout: Layout1)(
snapshotZ: StateSnapshot[Z]
)(f: StateSnapshot[Z] => StateSnapshot[A])(renderA: StateSnapshot[A] => VdomNode): VdomNode =
layout(renderA(f(snapshotZ)))
def render2[A, B, Z](layout: Layout2)(snapshotZ: StateSnapshot[Z])(
f1: StateSnapshot[Z] => StateSnapshot[A],
f2: StateSnapshot[Z] => StateSnapshot[B]
)(renderA: StateSnapshot[A] => VdomNode, renderB: StateSnapshot[B] => VdomNode): VdomNode =
layout(renderA(f1(snapshotZ)), renderB(f2(snapshotZ)))
case class Foo[Z, A](f: StateSnapshot[Z] => StateSnapshot[A], render: StateSnapshot[A] => VdomNode) {
val func: StateSnapshot[Z] => VdomNode = render compose f
}
def _render2[A, B, Z](fooA: Foo[Z, A], fooB: Foo[Z, B])(layout2: Layout2): StateSnapshot[Z] => VdomNode =
(fooA.func, fooB.func).mapN(layout2)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment