Skip to content

Instantly share code, notes, and snippets.

@puffnfresh
Created March 9, 2013 01:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save puffnfresh/5122114 to your computer and use it in GitHub Desktop.
Save puffnfresh/5122114 to your computer and use it in GitHub Desktop.
Interleaving HLists in Scala and shapeless.
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