Skip to content

idea for lazy flatMap#168

Merged
asfgit merged 4 commits intoapache:monad-modelfrom
noobymatze:monad-model
Apr 24, 2016
Merged

idea for lazy flatMap#168
asfgit merged 4 commits intoapache:monad-modelfrom
noobymatze:monad-model

Conversation

@noobymatze
Copy link
Copy Markdown
Contributor

I fixed the formatting and provided an idea for implementing flatMap in a lazy fashion.

This approach has two problems though:

1. For every call of getObject, setObject and detach the whole
   model chain will be evaluated again.
2. It's the same problem like with the implementation before.
   When the setObject is called and any value in the retrieval
   has been null, no object will be set, which is unlike the
   PropertyModel, which would initialize any values being null.
T object = IModel.this.getObject();
if (object != null)
{
IModel<R> model = mapper.apply(object);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result of mapper.apply() is used without checks in the other methods. I think they should have it too.

@martin-g
Copy link
Copy Markdown
Member

Thanks for the PR, Matthias!

Other Wicket devs seems to liked the idea of having those methods in IModel, so thanks for formatting the code too! :-)

This #flatMap() impl looks good to me!
Please add the checks for null to set/getObject and I'll merge it!

@noobymatze
Copy link
Copy Markdown
Contributor Author

Awesome! Should hopefully be fine now!

Thanks again for being so open to the ideas!

@asfgit asfgit merged commit a68dc57 into apache:monad-model Apr 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants