Skip to content

Commit

Permalink
add support for 2.11
Browse files Browse the repository at this point in the history
  • Loading branch information
timvw committed Oct 28, 2020
1 parent 30f27dc commit 9751fb1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions build.sbt
@@ -1,7 +1,7 @@

lazy val scala211 = "2.11.12"
lazy val scala212 = "2.12.12"
lazy val scala213 = "2.13.3"
lazy val supportedScalaVersions = List(scala212, scala213)
lazy val supportedScalaVersions = List(scala211, scala212, scala213)

organization := "be.icteam"
name := "stringmapper"
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/be/icteam/stringmapper/CsvParser.scala
Expand Up @@ -5,8 +5,8 @@ trait CsvParser[T] {
}

object CsvParser {
def apply[T : StringsToThing]: CsvParser[T] = {
(line: String) => {
def apply[T : StringsToThing]: CsvParser[T] = new CsvParser[T] {
def parse(line: String): MapResult[T] = {
val strings = line.split(",", -1)
implicitly[StringsToThing[T]].map(strings)
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/scala/be/icteam/stringmapper/StringToThing.scala
Expand Up @@ -10,8 +10,8 @@ trait StringToThing[T] {

object StringToThing {

def apply[T](fn: String => T): StringToThing[T] = {
(value: String) => {
def apply[T](fn: String => T): StringToThing[T] = new StringToThing[T] {
def map(value: String) = {
Try {
fn(value)
} match {
Expand All @@ -25,8 +25,8 @@ object StringToThing {
implicit val stringToInt: StringToThing[Int] = StringToThing[Int](_.toInt)
implicit val stringToDouble: StringToThing[Double] = StringToThing[Double](_.toDouble)

implicit def stringToOption[T: StringToThing]: StringToThing[Option[T]] = {
(value: String) => {
implicit def stringToOption[T: StringToThing]: StringToThing[Option[T]] = new StringToThing[Option[T]] {
def map(value: String) = {
if (value.isEmpty) {
MapResult.success(None)
}
Expand All @@ -37,8 +37,8 @@ object StringToThing {
}
}

implicit def stringTofieldType[K, H](implicit hParser: StringToThing[H]): StringToThing[FieldType[K, H]] = {
(line: String) => {
implicit def stringTofieldType[K, H](implicit hParser: StringToThing[H]): StringToThing[FieldType[K, H]] = new StringToThing[FieldType[K, H]] {
def map(line: String) = {
hParser.map(line) match {
case Left(msgs) => MapResult.failure(msgs: _*)
case Right(h) => MapResult.success(field[K].apply(h))
Expand Down
12 changes: 6 additions & 6 deletions src/main/scala/be/icteam/stringmapper/StringsToThing.scala
Expand Up @@ -9,15 +9,15 @@ trait StringsToThing[T] {

object StringsToThing {

implicit val stringsToHNil: StringsToThing[HNil] = {
(line: Array[String]) => {
implicit val stringsToHNil: StringsToThing[HNil] = new StringsToThing[HNil] {
def map(line: Array[String]): MapResult[HNil] = {
if(line.isEmpty) MapResult.success(HNil)
else MapResult.failure(s"expected end of line, but still have '${line.mkString(",")}'")
}
}

implicit def stringsToHList[K <: Symbol, H, T <: HList](implicit witness: Witness.Aux[K], hParser: Lazy[StringToThing[FieldType[K, H]]], tLineParser: StringsToThing[T]): StringsToThing[FieldType[K, H] :: T] = {
(line: Array[String]) => {
implicit def stringsToHList[K <: Symbol, H, T <: HList](implicit witness: Witness.Aux[K], hParser: Lazy[StringToThing[FieldType[K, H]]], tLineParser: StringsToThing[T]): StringsToThing[FieldType[K, H] :: T] = new StringsToThing[FieldType[K, H] :: T] {
def map(line: Array[String]) = {
if (line.isEmpty) MapResult.failure(s"unexpected end of line, still need to parse columns..")
else {
(hParser.value.map(line.head), implicitly[StringsToThing[T]].map(line.tail)) match {
Expand All @@ -30,8 +30,8 @@ object StringsToThing {
}
}

implicit def parser[T, R](implicit gen: LabelledGeneric.Aux[T, R], rparser: StringsToThing[R]): StringsToThing[T] = {
(line: Array[String]) => {
implicit def parser[T, R](implicit gen: LabelledGeneric.Aux[T, R], rparser: StringsToThing[R]): StringsToThing[T] = new StringsToThing[T] {
def map(line: Array[String]) = {
rparser.map(line) match {
case Left(msgs) => MapResult.failure(msgs: _*)
case Right(r) => MapResult.success(gen.from(r))
Expand Down

0 comments on commit 9751fb1

Please sign in to comment.