Last active
August 29, 2015 14:27
-
-
Save dgouyette/34bc4c750014c744e3a3 to your computer and use it in GitHub Desktop.
Bowling 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 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 | |
} | |
} |
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
Et as-tu vraiment besoin d'une HList pour stoquer seulement des Int ?