Comments (22)
This comment made me revisit the recent PR. I had implemented ReadStream & WriteStream as traits, but they have been removed from the classes they were applied to.
from mod-lang-scala.
ReadStream and WriteStream should be traits too, but TCPSupport and SSLSupport are used for applying the standard TCP and SSL properties which is somewhat different.
from mod-lang-scala.
I am vaguely remembering having a problem implementing the traits with actual code (rather than just the interface), because a trait can't have a constructor parameter - meaning we can't delegate to the internal mechanism. (Happy to be proved wrong here, of course).
I attempted to create a marker trait for those classes which wrap a o.v.j.core class, which exposed the delegate via a protected method (so the real traits could depend on that), but ended up down a rabbit hole. Maybe I'll try again.
from mod-lang-scala.
For scala classes which wraps a o.v.j.core class, we could use something like below:
private[core] abstract class ApiShim[T](private val internal: T) {
def unwrap: T = internal
}
from mod-lang-scala.
How would this be applied to the ReadStream trait to enable its methods to contain actual code, rather than just method signature declarations? I couldn't figure that out.
from mod-lang-scala.
Probably something like this?
abstract class ApiShim[T](private val internal: T) {
def unwrap: T = internal
}
trait ReadStream[T <: org.vertx.java.core.streams.ReadStream[T]] { self: ApiShim[T] =>
import org.vertx.scala.core.FunctionConverters._
def dataHandler(handler: (Buffer) => Unit) = {
unwrap.dataHandler(handler)
this
}
def endHandler(handler: () => Unit) = {
unwrap.endHandler(handler)
this
}
def exceptionHandler(handler: Handler[Throwable]) = {
unwrap.exceptionHandler(handler)
}
def pause() = {
unwrap.pause()
this
}
def resume() = {
unwrap.resume()
this
}
}
class NetSocket(val internal: JNetSocket) extends ApiShim[JNetSocket](internal) with org.vertx.scala.core.streams.ReadStream[JNetSocket] {
}
from mod-lang-scala.
Awesome. The 'self' thing is what was eluding me.
I tweaked the stream traits earlier; I'll have a go at applying this approach.
from mod-lang-scala.
I've given it a try in a branch; but this doesn't compile for reasons that escape me.
from mod-lang-scala.
I have fixed the compile errors, but there is a test failure. You could check https://github.com/raniejade/mod-lang-scala/tree/delegating_traits.
from mod-lang-scala.
Sorry the test failure was because of a dirty build. Did a clean build and everything passed.
from mod-lang-scala.
i think due to the self type it's now possible use a trait, the abstract member will be resolved or injected until the concrete class construction ... incidentally we get rid of the noisy constructor and/or indirect calls.
https://gist.github.com/edgarchan/5905937
from mod-lang-scala.
OK, all the above works for me.
On 2 July 2013 05:36, Edgar Chan [email protected] wrote:
i think due to the self type it's now possible use a trait, the abstract
member will be resolved or injected until the concrete class construction
... incidentally we get rid of the noisy constructor and/or indirect calls.https://gist.github.com/edgarchan/5905937
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/12#issuecomment-20326008
.
from mod-lang-scala.
I updated the branch, but the signature of Pump.scala newPump() doesn't seem right & the associated file test doesn't compile.
from mod-lang-scala.
I'm reading this: http://www.artima.com/weblogs/viewpost.jsp?thread=270195 and wondering if we should be using a type statement.
from mod-lang-scala.
Hmm.. That's interesting, gonna check it out! Thanks!. I somehow fixed the compile error, check this commit: raniejade@3ee2cd8
from mod-lang-scala.
great .. don't you think it's better to use the shorter version in this case .. ReadStream[_] instead of ReadStream[T] forSome {type T}
from mod-lang-scala.
Forgive my ignorance but are they exactly the same?
from mod-lang-scala.
i can't find a proper reference but look at this presentation, the relevant part is the Existential Types .. it can be used for sure.
slideshare.net/dgalichet/demystifying-scala-type-system
from mod-lang-scala.
Yeah, ReadStream[_]
and ReadStream[T] forSome {type T}
are the same :).
from mod-lang-scala.
@raniejade decided to take this on.
from mod-lang-scala.
@swilliams-vmw The link you have provided looks promising, I will try to take look at it further.
from mod-lang-scala.
This should be done with #63 too.
from mod-lang-scala.
Related Issues (20)
- is scala included in the latest vertx HOT 2
- Class cast exception when trying to deploy a verticle HOT 2
- An example problem on manual HOT 1
- Problem with Scala scripts in fat jar HOT 5
- Strange behavior with HttpServerResponse headers().put() and putHeader() HOT 1
- scala routerMatcher companion object with default java RouterMatcher argument? HOT 2
- Mod.json empty file HOT 1
- JsonObject and JsonArray should have (Scala) monad and higher-order functions HOT 1
- Script compilation fails with Scala 2.11 HOT 1
- Scripts fail to compile on Windows HOT 1
- Upgrade to Vert.x 2.1.2 HOT 1
- Integrate SBT migration manager plugin
- Add new Router for more idiomatic Scala HOT 1
- Increment version on master?
- Change VertxExecutionContext to run directly HOT 2
- error with latest mod-lang and scala 2.11.2 HOT 1
- Scala router - make RouterException a trait
- Unable to specify instance number on the command line HOT 2
- Scala class is run as a script HOT 4
- Having get parameters can lead to inconsistent results HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mod-lang-scala.