Skip to content

Instantly share code, notes, and snippets.

@kryptt
Last active August 17, 2020 10:44
Show Gist options
  • Save kryptt/0e65d7de2da4429059a1d4455a0fe326 to your computer and use it in GitHub Desktop.
Save kryptt/0e65d7de2da4429059a1d4455a0fe326 to your computer and use it in GitHub Desktop.
/* It is common for the system to have more complex structures that house transactions, and these complex structures are what the system is dealing with
It could be balance sheets as defined earlier, but lets pretend there are other structures used for Fraud detection as well...
They are optionally there along with some arbitray metadata, and we need to run a verifier across the transactions inside these structures
It would seem like a lot of very specific code is needed to get all this done; but in reality we already have all the combinators we need:
*/
def systemVerifier[S, Metadata](traversal: Traversal[S, Transaction], verifier: Pipe[IO, Transaction, Transaction]): Pipe[IO, (Option[S], Metadata), (Option[S], Metadata)] =
_.flatMap(
_1[(Option[S], Metadata), Option[S]]
.composePrism(some)
.composeTraversal(traversal)
.modifyF(Stream.emit(_).through(verifier)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment