Created
December 18, 2016 16:29
-
-
Save lforite/cad97cc0a47847b2e4177192d9dbc3ae to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| package dynamo.ast.write | |
| import dynamo.ast.DynamoType | |
| trait DynamoWrite[A] { self => | |
| def write(a: A): DynamoWriteResult[DynamoType] | |
| def map[B](f: (A => B)): DynamoWrite[B] //not yet coded, not sure if necessary | |
| } | |
| object DynamoWrite { | |
| def apply[A](f: (A => DynamoWriteResult[DynamoType])): DynamoWrite[A] = new DynamoWrite[A] { | |
| override def write(a: A): DynamoWriteResult[DynamoType] = f(a) | |
| } | |
| def write[A] = new WriteAt[A] | |
| class WriteAt[A] { | |
| def at(at: String)(implicit writes: DynamoWrite[A]): DynamoWritePath[A] = new DynamoWritePath[A] { | |
| override def path = at | |
| } | |
| } | |
| } | |
| trait DynamoWritePath[A] { | |
| def path: String | |
| def write(a: A)(implicit write: DynamoWrite[A]): DynamoWriteResult[(String, DynamoType)] = { | |
| write.write(a) map (dt => (path, dt)) | |
| } | |
| } | |
| sealed trait DynamoWriteResult[+A] { | |
| def map[B](f: (A => B)): DynamoWriteResult[B] = this match { | |
| case DynamoWriteSuccess(a) => DynamoWriteSuccess(f(a)) | |
| case e:DynamoWriteError => e | |
| } | |
| } | |
| case class DynamoWriteSuccess[A](a: A) extends DynamoWriteResult[A] | |
| case class DynamoWriteError(path: String, error: String) extends DynamoWriteResult[Nothing] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment