@@ -3,6 +3,22 @@ package shapelessex
3
3
import org .scalatest ._
4
4
import shapeless ._
5
5
6
+ object SizedHelper {
7
+ def row (cols : Seq [String ]) =
8
+ cols.mkString(" \" " , " \" , \" " , " \" " )
9
+
10
+ def csv [N <: Nat ](hdrs : Sized [Seq [String ], N ], rows : List [Sized [Seq [String ], N ]]) =
11
+ row(hdrs) :: rows.map(row(_))
12
+
13
+ val hdrs = Sized (" Title" , " Author" )
14
+
15
+ val rows = List (
16
+ Sized (" Types and Programming Languages" , " Benjamin Pierce" ),
17
+ Sized (" The Implementation of Functional Programming Languages" , " Simon Peyton-Jones" )
18
+ )
19
+ }
20
+
21
+
6
22
/** == Collections with statically known sizes ==
7
23
*
8
24
* shapeless provides collection types with statically known sizes. These can prevent runtime errors such as those that
@@ -27,23 +43,7 @@ import shapeless._
27
43
* @param name sized
28
44
*/
29
45
object SizedExercises extends FlatSpec with Matchers with exercise.Section {
30
-
31
- object Helper {
32
- def row (cols : Seq [String ]) =
33
- cols.mkString(" \" " , " \" , \" " , " \" " )
34
-
35
- def csv [N <: Nat ](hdrs : Sized [Seq [String ], N ], rows : List [Sized [Seq [String ], N ]]) =
36
- row(hdrs) :: rows.map(row(_))
37
-
38
- val hdrs = Sized (" Title" , " Author" )
39
-
40
- val rows = List (
41
- Sized (" Types and Programming Languages" , " Benjamin Pierce" ),
42
- Sized (" The Implementation of Functional Programming Languages" , " Simon Peyton-Jones" )
43
- )
44
- }
45
-
46
- import Helper ._
46
+ import SizedHelper ._
47
47
48
48
/** In the example below we define a method `csv` whose signature guarantees at compile time that there are exactly as many
49
49
* column headers provided as colums
0 commit comments