Skip to content

add answers to exercise 1-5 chapter 7 #30

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

Merged
merged 4 commits into from
Mar 27, 2016

Conversation

ryblovAV
Copy link
Contributor

Hi @axel22,
Pls see this answers

def second_=(x: Q)(implicit txn: InTxn) = rSecond.single.transform(old => x)

def swap()(implicit e: P =:= Q, txn: InTxn): Unit = {
val old = Ref[P](first)
Copy link
Member

Choose a reason for hiding this comment

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

It shouldn't be necessary to create a Ref object just to hold the value of the first field.
It is sufficient to read it via apply (i.e. just call first) and store the value of type P directly to the local variable.

val old = first

@axel22
Copy link
Member

axel22 commented Mar 25, 2016

Thanks, looking good overall!

I only left some minor comments for exercise 1.

@ryblovAV
Copy link
Contributor Author

@axel22
Thanks for your review, I'll try to fix

@ryblovAV
Copy link
Contributor Author

Hi @axel22,
Pls, see my changes

I use asInstanceOf[P] method to convert Q => P.
Pls suggest me, does a better way exist ?

@axel22
Copy link
Member

axel22 commented Mar 27, 2016

Unfortunately, not that I know of. Ideally, =:= class should have a reverse method that swaps the type parameters. Alternatively, you could require implicit =:= in both directions, but I guess this is good as it is!

LGTM

@axel22 axel22 merged commit 407a5cd into concurrent-programming-in-scala:master Mar 27, 2016
@axel22
Copy link
Member

axel22 commented Mar 27, 2016

Thanks for your contribution!

@ryblovAV
Copy link
Contributor Author

Thanks for the review

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.

2 participants