Skip to content

Instantly share code, notes, and snippets.

@dgouyette
Last active August 29, 2015 14:27
Show Gist options
  • Save dgouyette/34bc4c750014c744e3a3 to your computer and use it in GitHub Desktop.
Save dgouyette/34bc4c750014c744e3a3 to your computer and use it in GitHub Desktop.
Bowling shapeless
import org.scalatest._
import shapeless.{HList, HNil}
import shapeless._, nat._, shapeless.ops.hlist.{LeftReducer, Length}, ops.nat.{Mod, Prod, Sum}
object BowlingScoreShapeless {
type Manche = Int :: Int :: HNil
type DerniereManche = Int :: Int :: Int :: HNil
type Game = Manche :: HNil
def score(game: Game) = {
import XXXXXXXX._
val a = game.head.reduceLeft(XXXXXXXX)(Sum)
}
object Sum extends LeftReducer[Game, Int] {
override type Out = Int
override def apply(t: Game): Int =2
}
}
object XXXXXXXX extends Poly1 {
implicit def caseInt = at[Int](x => x)
//val game: Game = (0 :: 0 :: HNil) :: (0 :: 0 :: 0 :: HNil) :: HNil
}
class BowlingScoreShapelessSpec extends FlatSpec with ShouldMatchers {
import BowlingScoreShapeless._
"Une manche 0 + 0" should " doit avoir un score de 0" in {
score((0::0::HNil)::HNil) shouldEqual 0
}
"Une manche 3 + 1" should " doit avoir un score de 4" in {
score((3::1::HNil)::HNil) shouldEqual 4
}
}
@vil1
Copy link

vil1 commented Aug 18, 2015

Et as-tu vraiment besoin d'une HList pour stoquer seulement des Int ?

@dgouyette
Copy link
Author

Je veux pouvoir différencier Manche de DerniereManche, qui ont tous des Int, mais un nombre différent.
Le but est aussi de faire "mumuse" avec shapeless

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment