Created
May 9, 2011 06:09
-
-
Save kevinclark/962130 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[error] /private/var/greplin/src/widmore/src/main/scala/com/greplin/widmore/util/RichResource.scala:11: Parameter type in structural refinement may not refer to an abstract type defined outside that refinement | |
[error] def returnResource(loaner: T) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object RichResource { | |
type Resource[T] = { | |
def getResource: T | |
def returnResource(loaner: T) // Line 11 is right here | |
} | |
implicit | |
def resourceToRichResource[T](res: Resource[T]) = new RichResource[T](res) | |
} | |
class RichResource[T](resource: RichResource.Resource[T]) { | |
def loan[R](block: T => R): R = { | |
val loaner: T = resource.getResource | |
try { | |
block(loaner) | |
} finally { | |
resource.returnResource(loaner) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment