@@ -3,43 +3,43 @@ package shapelessex
3
3
import org .scalatest ._
4
4
import shapeless ._
5
5
6
+ object GenericHelper {
7
+ case class Foo (i : Int , s : String , b : Boolean )
8
+
9
+ val fooGen = Generic [Foo ]
10
+
11
+ val foo = Foo (23 , " foo" , true )
12
+
13
+ import poly ._
14
+
15
+ // Simple recursive case class family
16
+ sealed trait Tree [T ]
17
+ case class Leaf [T ](t : T ) extends Tree [T ]
18
+ case class Node [T ](left : Tree [T ], right : Tree [T ]) extends Tree [T ]
19
+
20
+ // Polymorphic function which adds 1 to any Int and is the identity
21
+ // on all other values
22
+ // format: OFF
23
+ object inc extends -> ((i : Int ) ⇒ i + 1 )
24
+ // format: ON
25
+ case class Book (author : String , title : String , id : Int , price : Double )
26
+ case class ExtendedBook (author : String , title : String , id : Int , price : Double , inPrint : Boolean )
27
+ }
28
+
29
+
6
30
/** == Generic representation of (sealed families of) case classes ==
7
31
*
8
32
* The `Iso`s of earlier shapeless releases have been completely reworked as the new `Generic` type, which closely
9
- * resembles the [generic programming capabilities introduced to GHC 7.2][ghcgeneric ].
33
+ * resembles the [[ https://wiki.haskell.org/GHC.Generics generic programming capabilities introduced to GHC 7.2 ]].
10
34
*
11
35
* `Generic[T]`, where `T` is a case class or an abstract type at the root of a case class hierarchy, maps between values
12
36
* of `T` and a generic sum of products representation (`HList`s and `Coproduct`s),
13
37
*
14
38
* @param name generic
15
39
*/
16
40
object GenericExercises extends FlatSpec with Matchers with exercise.Section {
41
+ import GenericHelper ._
17
42
18
- case class Foo (i : Int , s : String , b : Boolean )
19
-
20
- object Helper {
21
-
22
- val fooGen = Generic [Foo ]
23
-
24
- val foo = Foo (23 , " foo" , true )
25
-
26
- import poly ._
27
-
28
- // Simple recursive case class family
29
- sealed trait Tree [T ]
30
- case class Leaf [T ](t : T ) extends Tree [T ]
31
- case class Node [T ](left : Tree [T ], right : Tree [T ]) extends Tree [T ]
32
-
33
- // Polymorphic function which adds 1 to any Int and is the identity
34
- // on all other values
35
- // format: OFF
36
- object inc extends -> ((i : Int ) ⇒ i + 1 )
37
- // format: ON
38
- case class Book (author : String , title : String , id : Int , price : Double )
39
- case class ExtendedBook (author : String , title : String , id : Int , price : Double , inPrint : Boolean )
40
- }
41
-
42
- import Helper ._
43
43
/** {{{
44
44
* case class Foo(i: Int, s: String, b: Boolean)
45
45
*
0 commit comments