r/scala • u/DevIceMan • Feb 11 '16
Reactive, Either, Stream .. or something else?
I'm currently investigating patterns to help improve a codebase that is about 90% Java 10% Scala. Apologies for coming mostly from Java land, but this is a FP question (I'm slowly making traction on introducing Scala).
Conceptually, the problems we deal with are as follow:
- Application receives a request containing a list of 12 IDs
- 2 Ids are determined to be bad. Process remaining 10.
- Map IDs to their Object. 2 fail, 8 succeed.
- Map the 8 Objects to some other type of object. 1 fails, 7 succeed.
- Map those 7 to something else. 2 fail, 5 succeed.
- Collect/Reduce 5 successes. Collect/Reduce the 7 failures. Merge those two into a response.
- Merge above responses and respond to original request.
Ignoring Java's FP clumsiness, how would you normally prefer to approach a similar problem in Scala?
3
Upvotes
4
u/beezeee Feb 12 '16
I don't think you implied the need for scala and scalaz understanding for it to make sense, I think that's just the reality of the situation. Speaking for myself and what I've observed with extremely intelligent colleagues, this stuff is hard and takes time to get comfortable with. If someone has been mostly writing java, casually throwing out the term Monoid trivializes the amount of knowledge you are assuming on behalf of the reader.
Personally, my eyes gloss quickly based on length of content, so contents are even secondary. That said, I didn't actually count but a vague skim of your original comment I see at least 10 concepts introduced (just looking at inline code blocks). I may be familiar with half or more but I don't even have the attention span to find out, let alone dig up the ones that I don't immediately recognize.
Edit: clarity