kushalp
05/28/2020, 8:51 PMValid, Invalid and Either seamlessly? I'm thinking that this must be a fairly common pattern and would like to understand how others have done this in a simple way:
1. Make request to remote API that returns Either<ErrorException, ResponseData> where ResponseData is some data class
2. Validate all of the fields in ResponseData such that they can be converted into Invalid or Valid
3. Operate on the happy/sad pathsstojan
05/28/2020, 9:36 PMkushalp
05/28/2020, 9:45 PMkushalp
05/28/2020, 9:49 PMIO, returning Either<A, B>
2. API errors Left<A> so return a data class with all fields set to Invalid
API call successfully completes, validation fails
1. Call external API using IO, returning Either<A, B>
2. API succeeds with Right<B>, so validate all fields
3. Validation fails, so return a data class with all fields set to Invalid
4. This could be extended for partial validation, etc.
API completes, Validation completes
1. API returns Right<B>
2. Validation passes
3. data class is returned with all fields set to Validkushalp
05/28/2020, 9:50 PMkushalp
05/28/2020, 9:50 PMIO, Either, and Validated together feels a bit clunkythanerian
05/29/2020, 6:24 AM