Add fluent tuple destructuring with with() and withUni() methods #2022
hhfrancois
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Problem
When working with
Uni<TupleN>in reactive chains, destructuring tuples requires verbose and repetitive.getItemN()calls:This becomes increasingly difficult to read with:
flatMapcallsProposed Solution
Add helper methods to fluently destructure tuples directly in the reactive chain:
Compare with current verbose approach:
Key insight: The wrapper is hidden in the method signature, so callers see a fluent API similar to
Uni.combine().all().unis(...).with()without knowing it's a custom wrapper.API Design Options
Option 1: Standalone utility class (works today, no breaking changes)
This approach requires no modifications to Mutiny core - it's a simple helper utility that can be added to any project:
Advantages:
Option 2: Integrate with
.plug()via Subscribable interfacesCurrently
.plug()forces the return type to beUni<R>. This proposal suggests allowing.plug()to return a wrapper typeRthat implements aSubscribableinterface exposingwith()andwithUni():Current limitation:
Proposed generalization:
Rationale:
SubscribableNinterface has the correct typed signatures for N parametersplugN()method is type-safe and specific toUni<TupleN>SubscribableNguarantee they expose properly typedwith()andwithUni()methodsExample usage with plug2():
Advantages:
.plug()patternWithTuple::ofTuple2)Uni<TupleN>)Disadvantages:
plug2()throughplug9()) toUniinterfaceImplementation
I have a complete working implementation supporting
Tuple2throughTuple9with both:with(FunctionN<T1...TN, R>)- synchronous transformationwithUni(FunctionN<T1...TN, Uni<R>>)- asynchronous chaining (likeflatMap)Full implementation: See attached WithTuple.java
Key features:
FunctionNinterfaces for N>3 parametersExample Code
Usage Example:
Benefits
tuple.getItem1()Uni.combine().all().unis(...).with()Use Cases
flatMapchainsGist:
https://gist.github.com/hhfrancois/abc0e2303f82d112a823a580b71cd102
Beta Was this translation helpful? Give feedback.
All reactions