Skip to content
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

Add macros to create Trys #187

Merged
merged 1 commit into from
Dec 12, 2014
Merged

Add macros to create Trys #187

merged 1 commit into from
Dec 12, 2014

Conversation

johnynek
Copy link
Collaborator

These are just toy macros, but the fastAttempt in particular could make Injections a bit faster that are defined using it (rather than Inversion.attempt).

* that would still require calling apply on that function.
* In contrast, here, we can inline it directly.
*/
def fastAttempt[A, B](b: B)(inv: A): Try[A] = macro MacroImpl.fastAttempt[A, B]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does the inv type signature of A work here? since we can inline it at the callsite we can just take a FN B => A and do it in place? nifty

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

inv is basically a lazy parameter that is inlined (same idea as fastTry).

val maybeNum = "12"
fastAttempt(maybeNum)(maybeNum.toInt)

I assume that if we put just the function, it will inline the function object and then call the apply on it. To do otherwise, I assume will take a Tree that we need to walk.

@ianoc
Copy link
Collaborator

ianoc commented Dec 12, 2014

LGTM, merge when green

johnynek added a commit that referenced this pull request Dec 12, 2014
@johnynek johnynek merged commit 687a482 into develop Dec 12, 2014
@johnynek johnynek deleted the fastTryMacro branch December 12, 2014 19:09
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.

None yet

2 participants