-
-
Notifications
You must be signed in to change notification settings - Fork 646
Add Value.to() general conversion methods #3018
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Thanks for your submission! I got it, and I need some time to think it through. I need to weigh pros and cons - there's some overlap with |
IMHO The new To illustrate the idea, let's see how to rewrite some of the existing
I am using a lot this approach combined with my JoyTools Commons Library containing many singleton conversion functions: Element : get an element from any
Java : conversion to JDK data structures.
Guava : conversion to Guava's data structures.
Vavr : conversion to Vavr'sdata structures.
Let's combine all the above with some easy examples: Get the only existing element
Get the first existing element as a Java
Similar to the above, get the first existing element as a Vavr
Create a new Guava BiMap
Create a new case insensitive Vavr SortedMap
Create a new case insensitive Java SortedMap
Create a new Java concurrentHashMap
Create a new Guava Table
The advantages of this approach:
Hope this may help to clarify why I consider this proposal so interesting and stylistically noteworthy ;-) |
There are lot of useful type conversion to turn a
Value
into another well known data type, such asjava.util.List
,java.util.Map
,io.vavr.collection.Map
, etc.The goal of this request is adding to
Value
a new genericto(Function)
method in order to enable the conversion of a Value into a custom type by using a fluent syntax, as per following example:This is also useful to enhance interoperability with other library data types, such as:
Table
,ImmutableList
, etcBag
,MultiMap
, etcThere are other 3 variants to deal with more advanced convertions when the conversion
Function
takes in input anIterable
ofTuple2
,Tuple3
orTuple4
, as per following example: