Created
March 9, 2013 01:49
-
-
Save puffnfresh/5122114 to your computer and use it in GitHub Desktop.
Interleaving HLists in Scala and shapeless.
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
import shapeless._ | |
// fogus wanted this: | |
// [a] -> [b] -> [a b a b ...] | |
// Follow up question: "Do you know a dependent language with my interleave?" | |
// Yes. Scala and shapeless even make it a single line! | |
object Fogus { | |
val a = 1 :: true :: "three" :: HNil | |
val b = "four" :: 5 :: false :: HNil | |
(a :: b :: HNil).transpose.flatMap(identity) | |
// 1 :: four :: true :: 5 :: three :: false :: HNil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment