trash - How to use intermediate result of Reads with another Reads -
the example have validating credit card number string. validations 1) issuer should exist credit card number, , 2) issuer should accepted 1 merchant.
here's work have far. ideally, use intermediate result issuer
first reads in next reads. there better way?
reads.filter[string](validationerror("invalid issuer")) { cardnumber => findissuer(cardnumber).isdefined // option[issuer] } andthen reads.filter[string](validationerror("issuer not accepted")) { cardnumber => // issuer, check issuer accepted merchant }
it's not direct answer, might consider write logic for/yield
expression:
val result: either[string, issuer] = { card <- json.validate[card].aseither.leftmap(_ => "reading error") issuer <- findissuer(card.number) //returns either[string, _] _ <- isaccepted(issuer) // returns either[string,_] } yield issuer
p.s. it's gateway case start using scalaz validation
.
Comments
Post a Comment