I’m not married to the name (I suggested apply). “with” also works. The 
originating goal was to allow custom alignment methods for those developers not 
satisfied with String::align(). String would logically be the result. 
“transform" became generic when the case was made that other types might also 
be relevant.

Example:

        import mystuff.HTMLDocument;

        HTMLDocument html = `
                       <html>
                           <body>
                               <p>Hello World.</p>
                           </body>
                       </html>
                  `.transform(HTMLDocument::parse);

Not a strong argument. Along with Remi’s request for primitive variants, I 
might be lead back to just supporting String.

Cheers,

— Jim


> On Sep 19, 2018, at 10:25 AM, Stephen Colebourne <scolebou...@joda.org> wrote:
> 
> On Tue, 18 Sep 2018 at 18:57, Jim Laskey <james.las...@oracle.com> wrote:
>> 
>> Please review the API for String::transform. The goal is to provide a String 
>> instance method to allow function application of custom transformations 
>> applied to an instance of String.
>> 
>> csr: https://bugs.openjdk.java.net/browse/JDK-8203703
>> jbs: https://bugs.openjdk.java.net/browse/JDK-8203442
> 
> The similar method in java.time.* is named `with`
> https://download.java.net/java/early_access/jdk11/docs/api/java.base/java/time/LocalDate.html#with(java.time.temporal.TemporalAdjuster)
> 
> String capped =
>  title.with(Example::naiveDropFirstWord);
>       .with(Example::naiveTitleCase)
>       .concat(".");
> 
> However, I note that this method is designed to return any type, not
> just String (making it a different kind of method). But *why* return
> any type? The motivation for doing so is not clear from the CSR.
> 
> Stephen

Reply via email to