Created
January 9, 2020 11:46
-
-
Save happy-bracket/c3aaa4f6c18691ac4de7364e54161105 to your computer and use it in GitHub Desktop.
HList, but in Kotlin!
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
sealed class HList<T> | |
object HNil : HList<Nothing>() | |
data class HNode<T, H : HList<*>>( | |
val value: T, | |
val next: H | |
) : HList<H>() | |
infix fun <A, B> A.hcons(b: B): HNode<B, HNode<A, HNil>> = | |
HNode(b, HNode(this, HNil)) | |
infix fun <A, H : HList<*>> H.hcons(a: A): HNode<A, H> = | |
HNode(a, this) | |
val hlist: HNode<Long, HNode<Int, HNode<String, HNode<Boolean, HNil>>>> = | |
true hcons "sss" hcons 3 hcons 4L |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cool, but I think the
T
type param in HList, is not necessary.