Skip to content

Commit

Permalink
ammend example
Browse files Browse the repository at this point in the history
  • Loading branch information
timvw committed Nov 2, 2020
1 parent cdf6f02 commit d420d5d
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -32,10 +32,12 @@ Customizing StringToThing:
val stringToItem: StringsToThing[Item] = {

implicit def customIntFieldParser[K <: Symbol]: StringToThing[FieldType[K, Int]] = {
// in this example we trim eventual whitespace
StringToThing.stringTofieldType[K, Int](StringToThing[Int](_.trim.toInt))
}

implicit def customStringFieldParser[K <: Symbol](implicit witness: Witness.Aux[K]): StringToThing[FieldType[K, String]] = {
// in this example we UPPERCASE the value of the 'name' field
val nameParser = StringToThing[String](_.toUpperCase())
val hParserToUse =
if(witness.value == Symbol("name")) nameParser
Expand All @@ -48,6 +50,7 @@ val stringToItem: StringsToThing[Item] = {

implicit val customStringToItem = stringToItem
val customItemCsvParser = CsvParser[Item]
// the whitespace in ' 3' is ignored and name is in uppercase
assert(customItemCsvParser.parse(malformedLeadingSpaceInId) == Right(Item("sir", "MIKE", 3, Some("x"))))
```

Expand Down

0 comments on commit d420d5d

Please sign in to comment.