Skip to content

Commit

Permalink
coproduct reader
Browse files Browse the repository at this point in the history
  • Loading branch information
pathikrit committed Jun 4, 2017
1 parent 737939e commit cf2d718
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
3 changes: 1 addition & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ lazy val commonSettings = Seq(
"-Ywarn-unused:params", // Warn if a value parameter is unused.
"-Ywarn-unused:patvars", // Warn if a variable bound in a pattern is unused.
"-Ywarn-unused:privates", // Warn if a private member is unused.
"-Ywarn-value-discard", // Warn when non-Unit expression results are unused.
"-language:reflectiveCalls"
"-Ywarn-value-discard" // Warn when non-Unit expression results are unused.
),
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.2" % Test,
updateImpactOpenBrowser := false
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/better/files/Scanner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ object Scanner {
override def close() = reader.close()
}

val stdin = Scanner(System.in)(Config.default)
val stdin: Scanner = Scanner(System.in)(Config.default)

/**
* Use this to configure your Scanner
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/better/files/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ package object files extends Implicits {
* Default array buffer size
* Seems like a good value used by JDK: (see: java.io.BufferedInputStream.DEFAULT_BUFFER_SIZE)
*/
private[files] val defaultBufferSize = 8192
val defaultBufferSize = 8192

/**
* The default charset used by better-files
Expand Down
10 changes: 10 additions & 0 deletions shapeless/src/main/scala/better/files/ShapelessScanner.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package better.files

import better.files.Scanner.Read

import shapeless._

import scala.util.Try

object ShapelessScanner {
implicit val hNilScannable: Scannable[HNil] =
Scannable(_ => HNil)
Expand All @@ -11,4 +15,10 @@ object ShapelessScanner {

implicit def genericScannable[A, R](implicit gen: Generic.Aux[A, R], reprScannable: Lazy[Scannable[R]]): Scannable[A] =
Scannable(s => gen.from(reprScannable.value(s)))

implicit val cnilReader: Read[CNil] =
Read(_ => throw new IllegalStateException())

implicit def coproductReader[H, T <: Coproduct](implicit h: Read[H], t: Read[T]): Read[H :+: T] =
Read(s => Try(Inl(h(s))).getOrElse(Inr(t(s))))
}

0 comments on commit cf2d718

Please sign in to comment.