Giter VIP home page Giter VIP logo

Comments (22)

swilliams-pivotal avatar swilliams-pivotal commented on June 25, 2024

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.

purplefox avatar purplefox commented on June 25, 2024

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.

swilliams-pivotal avatar swilliams-pivotal commented on June 25, 2024

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.

raniejade avatar raniejade commented on June 25, 2024

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.

swilliams-pivotal avatar swilliams-pivotal commented on June 25, 2024

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.

raniejade avatar raniejade commented on June 25, 2024

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.

swilliams-pivotal avatar swilliams-pivotal commented on June 25, 2024

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.

swilliams-pivotal avatar swilliams-pivotal commented on June 25, 2024

I've given it a try in a branch; but this doesn't compile for reasons that escape me.

https://github.com/vert-x/mod-lang-scala/blob/delegating_traits/src/main/scala/org/vertx/scala/core/streams/ReadStream.scala

from mod-lang-scala.

raniejade avatar raniejade commented on June 25, 2024

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.

raniejade avatar raniejade commented on June 25, 2024

Sorry the test failure was because of a dirty build. Did a clean build and everything passed.

from mod-lang-scala.

edgarchan avatar edgarchan commented on June 25, 2024

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.

swilliams-pivotal avatar swilliams-pivotal commented on June 25, 2024

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.

swilliams-pivotal avatar swilliams-pivotal commented on June 25, 2024

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.

swilliams-pivotal avatar swilliams-pivotal commented on June 25, 2024

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.

raniejade avatar raniejade commented on June 25, 2024

Hmm.. That's interesting, gonna check it out! Thanks!. I somehow fixed the compile error, check this commit: raniejade@3ee2cd8

from mod-lang-scala.

edgarchan avatar edgarchan commented on June 25, 2024

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.

swilliams-pivotal avatar swilliams-pivotal commented on June 25, 2024

Forgive my ignorance but are they exactly the same?

from mod-lang-scala.

edgarchan avatar edgarchan commented on June 25, 2024

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.

raniejade avatar raniejade commented on June 25, 2024

Yeah, ReadStream[_] and ReadStream[T] forSome {type T} are the same :).

from mod-lang-scala.

galderz avatar galderz commented on June 25, 2024

@raniejade decided to take this on.

from mod-lang-scala.

raniejade avatar raniejade commented on June 25, 2024

@swilliams-vmw The link you have provided looks promising, I will try to take look at it further.

from mod-lang-scala.

Narigo avatar Narigo commented on June 25, 2024

This should be done with #63 too.

from mod-lang-scala.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.