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

Create some Scala Magic in response to the new OptionalBinder. #31

Merged
merged 1 commit into from
Oct 25, 2014

Conversation

nbauernfeind
Copy link
Member

This fixes #22.

In particular, I added all of the necessary scala magic to be able to ask for Option[T], Option[Provider[T]] and Option[javax.inject.Provider[T]] instead of the Guava Optional equivalents. This is solved similarly to how ScalaMultibinder is implemented. The readme is updated as well.

This pull request only shares a single commit from the other commit, specifically 2145abf (adding new injector extension methods).

@nbauernfeind nbauernfeind changed the title Create some Scala Magic in respons to the new OptionalBinder. Create some Scala Magic in response to the new OptionalBinder. Oct 5, 2014
@tsuckow
Copy link
Member

tsuckow commented Oct 15, 2014

I am making my way through this. I did notice that the OptionProviderSpec was missing a test for when the Optional is absent, I added it in my local copy.

I still need to sift through the Binder. I am on travel the next few days so whatever I don't finish tonight will have to wait till at least the weekend.

@tsuckow
Copy link
Member

tsuckow commented Oct 15, 2014

I am unfamiliar with the higherKinds flag. The library seems to compile fine without it, what is this needed for?

@nbauernfeind
Copy link
Member Author

That was a refactoring miss in this changeset; I'll remove it and update. That should only be in package.scala now.

It's the thing that allows me to do this:

private[scalaguice] type HKClassTag[CC2[_]] = ClassTag[CC2[_]]

  private[scalaguice] class WrapHelper[WType[_] : HKClassTag] {
    def around[T](typ: TypeLiteral[T]): TypeLiteral[WType[T]] = {
      val wType = Types.newParameterizedType(implicitly[HKClassTag[WType]].runtimeClass, typ.getType)
      TypeLiteral.get(wType).asInstanceOf[TypeLiteral[WType[T]]]
    }
  }

 private[scalaguice] def wrap[WType[_] : HKClassTag] = new WrapHelper[WType]

Specifically you can make a Manifest that takes a type parameter. I use it here to create a nice type-safe utility to wrap some T inside of some container (like a Set) by calling wrap[Set].around(typeLiteralOfT).

@tsuckow tsuckow merged commit 9f1e510 into codingwell:develop Oct 25, 2014
@tsuckow
Copy link
Member

tsuckow commented Oct 25, 2014

One down.

@tsuckow
Copy link
Member

tsuckow commented Oct 25, 2014

I just noticed that there are no tests for None in ScalaOptionBinder. That could be improved in a separate commit.

@nbauernfeind nbauernfeind deleted the ScalaOptionBinder branch October 25, 2014 14:39
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.

Can someone Inject something that is Optional ?
2 participants