Created
November 23, 2011 17:48
-
-
Save OleTraveler/1389344 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def lineToOffer(line: String, headers: List[String]) : Validation[NonEmptyList[String], Offer] = { | |
({commaSplit(_)} andThen {extractFields(_: List[String], headers)} apply line) :-> | |
{(v) => Offer(v._1, v._2, v._3, v._4)} | |
} | |
def commaSplit(l: String): String => List[String] = l.split(",").toList | |
def extractFields(x: List[String], headers: List[String]): Validation[NonEmptyList[String], (String, String, String, String)] = { | |
notEmpty(x(headers.indexOf("offer_name")), "No offer name specified on line:" + x.mkString(","))) <|***|> ( | |
notEmpty(x(headers.indexOf("email")), "No email specified on line:" + x.mkString(",")), | |
notEmpty(x(headers.indexOf("uuid")), "No uuid specified on line:" + x.mkString(",")), | |
notEmpty(x(headers.indexOf("reward_name")), "No uuid specified on line:" + x.mkString(",")) | |
) | |
} | |
case class Offer(offerName: String, email: String, uuid: String, rewardName: String) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can leave off some of that syntax - e.g. write
(g _ andThen f)(x)
Maybe write extractFields in curried form, with args reversed, e.g.
extractFields(headers:List)(x:List) = ...
, and then you could write(g _ andThen extractFields(headers))
Also, if you declare functions with val
f = (x:...) =>...
instead ofdef f(x:...) = ...
, you can leave off the trailing_
in those cases.