roookeee / datus

datus enables you to define a conversion process between two data structures in a fluent functional API
MIT License
41 stars 5 forks source link

ISSUE-21(#21): Add a nullsafe mode #22

Closed roookeee closed 5 years ago

roookeee commented 5 years ago

An implementation for #21:

roookeee commented 5 years ago

Still unsure if I will stick with the nullsafe() approach. Will reconsider the name too

roookeee commented 5 years ago

The shown code in #21 looks like this atm and performs nearly twice as fast for a prototype implementation of datus I did for this benchmark suite :

.from(Order::getCustomer).nullsafe()
    .map(Customer::getBillingAddress)
    .map(Address::getCity)
    .into(OrderDTO::setBillingCity)

The performance gains are expected as given() is quite heavy compared to a simple null propagation. We are only ~4-5x slower than a hand-rolled implementation now :)

roookeee commented 5 years ago

Switched to a SafetyMode enum instead of a boolean flag to be extendable in the future without breaking compatability as fast. It's also more descriptive

roookeee commented 5 years ago

I feel like this PR is done :)