Skip to content

Don't include Sized section until we have exercises #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/scala/shapeless/ShapelessLib.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ object ShapelessLib extends exercise.Library {
LensesExercises,
AutoTypeClassExercises,
LazyExercises,
SizedExercises,
// SizedExercises,
TypeSafeCastExercises,
TypeCheckingExercises
)
Expand Down
34 changes: 17 additions & 17 deletions src/main/scala/shapeless/SizedExercises.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@ package shapelessex
import org.scalatest._
import shapeless._

object SizedHelper {
def row(cols: Seq[String]) =
cols.mkString("\"", "\", \"", "\"")

def csv[N <: Nat](hdrs: Sized[Seq[String], N], rows: List[Sized[Seq[String], N]]) =
row(hdrs) :: rows.map(row(_))

val hdrs = Sized("Title", "Author")

val rows = List(
Sized("Types and Programming Languages", "Benjamin Pierce"),
Sized("The Implementation of Functional Programming Languages", "Simon Peyton-Jones")
)
}


/** == Collections with statically known sizes ==
*
* shapeless provides collection types with statically known sizes. These can prevent runtime errors such as those that
Expand All @@ -27,23 +43,7 @@ import shapeless._
* @param name sized
*/
object SizedExercises extends FlatSpec with Matchers with exercise.Section {

object Helper {
def row(cols: Seq[String]) =
cols.mkString("\"", "\", \"", "\"")

def csv[N <: Nat](hdrs: Sized[Seq[String], N], rows: List[Sized[Seq[String], N]]) =
row(hdrs) :: rows.map(row(_))

val hdrs = Sized("Title", "Author")

val rows = List(
Sized("Types and Programming Languages", "Benjamin Pierce"),
Sized("The Implementation of Functional Programming Languages", "Simon Peyton-Jones")
)
}

import Helper._
import SizedHelper._

/** In the example below we define a method `csv` whose signature guarantees at compile time that there are exactly as many
* column headers provided as colums
Expand Down