Created
December 26, 2017 22:51
-
-
Save trepidacious/e63bc137901eb8e2bb9cd7f87d50c553 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
case Put(create) => State(s => { | |
// Id and revision for the new data we will create | |
val id = Id[A](Guid(s.deltaId.clientId, s.deltaId.clientDeltaId, WithinDeltaId(s.currentGuidId))) | |
val revision = Guid(s.deltaId.clientId, s.deltaId.clientDeltaId, WithinDeltaId(s.currentGuidId + 1)) | |
// Make the data item | |
val createDIO = create(id.asInstanceOf[Id[U with A]]) | |
// Remember to increment guid twice for the guid and revision we generated | |
val stateWithA: (StateData[U], A) = createDIO.foldMap(arrow).run(s.withNextGuidId.withNextGuidId).value | |
// We know that Put requires A <: U, | |
// so the instanceOfs are safe | |
val newAddedRefs = AddedRef[U](id.asInstanceOf[Id[U]], stateWithA._2.asInstanceOf[U], revision) :: stateWithA._1.addedRefs | |
(stateWithA._1.copy(addedRefs = newAddedRefs), stateWithA._2) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment