I'd like to build a Parser that can take a Map input and output a Case class. Right now I have some imperative style code that doesn't seem to take advantage of FP. I just can't see how to build a Parser that can output a Case class.
Here is what I have:
def fromMap(m: Map[String,AttributeValue]): User = {
val id = m.get("user-id") map {_.getS}
val email = m.get("email").get.getS
val name = m.get("name").get.getS
val openId = m.get("openId") map {_.getS}
User(id, email, name, openId)
}
UPDATE : I guess I should have been more clear that I would like to do something similar to Anorm but with the Parser Combinators in scala. The problem with the above is that is not flexible or reusable. The caller has to just take what they get.
I'm hoping that parser combinators will be the right approach for parsing results in Map form. As you might have guessed I'm working with DyanmoDB.
UPDATE 2 : Apparently I can't explain the problem very well. All I want to do is write one or more Pareser Combinators that can transform a Map to a Case class of the caller's choosing using bindings specified by the caller. Input Map => Output Case Class
UPDATE 3 : https://github.com/wfaler/scala-dynamo looks interesting but doesn't use Parser Combinators.