Alejandro Ramos
04/01/2024, 7:33 AMdata class FooList(val values: Set<Foo>) : Set<Foo> by values {
companion object {
fun bar(fooValues: Set<String>): EitherNel<Foo.FooError, FooList> = either {
FooList(
fooValues.mapOrAccumulate { Foo.fromUser(it).bind() }.bind().toSet()
)
}
}
}
Where Foo.fromUser
returns an Either<FooError, Foo>
I’m trying to iterate through the fooValues and while creating Foo Objects, validating them and adding up the errors. (Have to do it inside Foo for reasons)
My question is, is there a cleaner way to implement this?
I thought I could use map and then bindAll() here but it wasn’t possible, seems like this mapOrAccumulate with two binds is the best option?
Sorry if it’s a stupid question, but thank you in advance for the response! arrowCLOVIS
04/01/2024, 7:54 PM.bind
CLOVIS
04/01/2024, 7:57 PMAlejandro Ramos
04/02/2024, 2:12 AMCLOVIS
04/02/2024, 7:56 AMAlejandro Ramos
04/02/2024, 8:53 AMCLOVIS
04/02/2024, 9:00 AM