Skip to content

Instantly share code, notes, and snippets.

@kubukoz
Last active July 28, 2018 19:52
Show Gist options
  • Save kubukoz/7c2f89a49841889298dd90947a66bec0 to your computer and use it in GitHub Desktop.
Save kubukoz/7c2f89a49841889298dd90947a66bec0 to your computer and use it in GitHub Desktop.
Mapping non-unary higher kinded types to unary higher kinded types to deal with https://youtrack.jetbrains.com/issue/SCL-12892
//works with Kleisli/ReaderT
implicit class NestedToUnary[F[_[_], _, _], G[_], I, O](private val value: F[G, I, O]) extends AnyVal {
type H[A] = F[G, I, A]
def unaryKind: H[O] = value
}
//works with fs2.Stream, Free/AuthedService from http4s
implicit class NestedToUnary2[F[_[_], _], G[_], I](private val value: F[G, I]) extends AnyVal {
type H[A] = F[G, I]
def unaryKind: H[O] = value
}
//works with Either, Validated
implicit class BinaryToUnary[F[_, _], A, B](private val value: F[A, B]) extends AnyVal {
type H[T] = F[A, T]
def unaryKind: H[B] = value
}
//etc.
//Usage:
val result: ValidatedNel[Error, User] = (
UserId(0).validNel.unaryKind,
emailV.unaryKind,
passV.unaryKind
).mapN(User)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment