We could also opt to rename map(...) to to(...)

Model.of(account).to(Account::getPerson).to(Person::getLastName).to(String::toUppercase)

Martijn


On Thu, Nov 17, 2016 at 11:09 AM, Emond Papegaaij
<[email protected]> wrote:
> I also think 'chained' better covers the intent. 'map' normally isn't
> a read/write transformation.
>
> Emond
>
> On Thu, Nov 17, 2016 at 12:38 AM, Martin Grigorov <[email protected]> 
> wrote:
>> +1 for #chained() .
>>
>> Martin Grigorov
>> Wicket Training and Consulting
>> https://twitter.com/mtgrigorov
>>
>> On Tue, Nov 15, 2016 at 10:07 PM, Sven Meier <[email protected]> wrote:
>>
>>> Hi,
>>>
>>> >We could rename the methods taking an IModel as first parameter to
>>> >"chained" or "from".
>>>
>>> or "map":
>>>
>>>     LambdaModel.map(IModel, SerializableFunction, SerializableBiConsumer)
>>>
>>>     LambdaModel.map(IModel, SerializableFunction)
>>>
>>> Sven
>>>
>>>
>>>
>>> Am 15.11.2016 um 20:52 schrieb Emond Papegaaij:
>>>
>>>> IModel.map(Function) indeed is functionally equivalent to
>>>> LambdaModel.of(IModel, Function), but its memory footprint is
>>>> significantly larger (120 vs 80 bytes). Also, there's no equivalent
>>>> method for of(IModel, Function, BiConsumer). Naturally, we can add the
>>>> corresponding method, but it will remain much less efficient. These
>>>> chained models require an additional object.
>>>>
>>>> We've ran into similar problems many times at Topicus. Javac still is
>>>> very buggy when it comes to lambda type inference. IMHO the best
>>>> solution is to simply rename the methods to prevent the collisions.
>>>>
>>>> We could rename the methods taking an IModel as first parameter to
>>>> "chained" or "from". Another solution would be a builder API, but I
>>>> doubt that would make the code more readable.
>>>>
>>>> Best regards,
>>>> Emond
>>>>
>>>> On Tue, Nov 15, 2016 at 8:06 PM, Martin Grigorov <[email protected]>
>>>> wrote:
>>>>
>>>>> On Tue, Nov 15, 2016 at 2:51 PM, Emond Papegaaij <
>>>>> [email protected]
>>>>>
>>>>>> wrote:
>>>>>> It seems I've hit a bug in javac:
>>>>>> LambdaModelTest[46,61] reference to of is ambiguous:
>>>>>> <T>   of(SerializableSupplier<T>, SerializableConsumer<T>)
>>>>>> <X,T> of(IModel<X>,               SerializableFunction<X,T>)
>>>>>>
>>>>>> This clearly is wrong:
>>>>>> IModel<String> personNameModel = LambdaModel.of(
>>>>>>      () -> person.getName(),
>>>>>>      (name) -> person.setName(name));
>>>>>>
>>>>>> The first parameter could match both SerializableSupplier<T> and
>>>>>> IModel<X>,
>>>>>> but the second parameter only matches SerializableConsumer<T>. Eclipse
>>>>>> has
>>>>>> no
>>>>>> problem with this and compiles the code just fine.
>>>>>>
>>>>>> I guess it confuses it with SerializableFunction<String, Void>.
>>>>> Although, I
>>>>> agree it should return null to actually match.
>>>>>
>>>>> IMO we don't
>>>>> need org.apache.wicket.model.LambdaModel#of(org.apache.wicket.
>>>>> model.IModel<X>,
>>>>> org.danekja.java.util.function.serializable.SerializableFunction<X,T>)
>>>>> It gives the same
>>>>> as org.apache.wicket.model.IModel#map(SerializableFunction<? super T, R>
>>>>> mapper).
>>>>>
>>>>>
>>>>> This now surfaces due to the change in the constructor. This testcase
>>>>>> used
>>>>>> to
>>>>>> call new LambdaModel(...), which had the same signature as the first
>>>>>> 'of'.
>>>>>> I
>>>>>> had to change it to use the overloaded factory method.
>>>>>>
>>>>>> I see two possible solutions:
>>>>>>   - Change the name of the factory methodes, so they are no longer
>>>>>> overloaded
>>>>>> (suggestions for the names are welcome)
>>>>>>   - Add a cast to the calling code to circumvent the bug.
>>>>>>
>>>>>> IMHO both are ugly.
>>>>>>
>>>>>> Best regards,
>>>>>> Emond
>>>>>>
>>>>>> On dinsdag 15 november 2016 13:36:56 CET [email protected] wrote:
>>>>>>
>>>>>>> The Buildbot has detected a new failure on builder wicket-master while
>>>>>>> building wicket. Full details are available at:
>>>>>>> https://ci.apache.org/builders/wicket-master/builds/550
>>>>>>>
>>>>>>> Buildbot URL: https://ci.apache.org/
>>>>>>>
>>>>>>> Buildslave for this Build: bb_slave1_ubuntu
>>>>>>>
>>>>>>> Build Reason: The SingleBranchScheduler scheduler named
>>>>>>> 'on-wicket-master-commit' triggered this build Build Source Stamp:
>>>>>>>
>>>>>> [branch
>>>>>>
>>>>>>> master] b40e9e1cd9ad7a9ffc63ab6c329c8d9c8b78b924 Blamelist: Emond
>>>>>>>
>>>>>> Papegaaij
>>>>>>
>>>>>>> <[email protected]>
>>>>>>>
>>>>>>> BUILD FAILED: failed compile
>>>>>>>
>>>>>>> Sincerely,
>>>>>>>   -The Buildbot
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>



-- 
Become a Wicket expert, learn from the best: http://wicketinaction.com

Reply via email to