Skip to content

Instantly share code, notes, and snippets.

@mjhopkins
Created June 25, 2015 03:08
Show Gist options
  • Save mjhopkins/997bedce7c206115a260 to your computer and use it in GitHub Desktop.
Save mjhopkins/997bedce7c206115a260 to your computer and use it in GitHub Desktop.
object CreateSequence {
import com.github.nscala_time.time.Implicits._
import Sequences._
val seq: Seq3[Int, String, Double] = an[Int].within(5.minutes)[String].within(10.minutes)[Double]
}
object Sequences {
def an[A] = new SeqBuilder[A]
def a[A] = new SeqBuilder[A]
class SeqBuilder[A] { def within(d: Duration) = new Seq2Builder[A](d) }
class Seq2Builder[A](duration: Duration) { def apply[B] = Seq2[A, B](duration) }
class Seq3Builder[A, B](d1: Duration, d2: Duration) { def apply[C] = Seq3[A, B, C](d1, d2) }
class Seq4Builder[A, B, C](d1: Duration, d2: Duration, d3: Duration) { def apply[D] = Seq4[A, B, C, D](d1, d2, d3) }
case class Seq2[A, B](d: Duration) { def within(duration: Duration) = new Seq3Builder[A, B](d, duration) }
case class Seq3[A, B, C](d1: Duration, d2: Duration) { def within(duration: Duration) = new Seq4Builder[A, B, C](d1, d2, duration) }
case class Seq4[A, B, C, D](d1: Duration, d2: Duration, d3: Duration)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment