-
-
Save runarorama/1389372 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