Last active
July 28, 2018 19:52
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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