Giter Club home page Giter Club logo

vertx-lang-scala's Introduction

Using it

After building this project you can start using it with the following prototype:

Vert.x Scala Lang SBT-starter

If you want to play with Vert.x-web and the security modules check out and build:

Vert.x Scala Lang Stack

Decisions and how they came to be

Why currying?

Everywhere a handler is used the API looks like this:

def sendWithHandler[T](address: String, message: AnyRef)( replyHandler: io.vertx.core.AsyncResult [io.vertx.scala.core.eventbus.Message[T]] => Unit) ...

The methods are curried for a simple reason: Scala type inference. Using the above method would look like like this:

vertx.eventBus.sendWithHandler[String]("hello", "msg")(reply => ...)

This is pretty straight forward. Let's look at an example without currying.

def sendWithHandler[T](address: String, message: AnyRef, replyHandler: io.vertx.core.AsyncResult [io.vertx.scala.core.eventbus.Message[T]] => Unit) ...

While difference in the API is pretty small, using it becomes awkward:

vertx.eventBus.sendWithHandler[String]("hello", "msg", (reply: AsyncResult [io.vertx.scala.core.eventbus.Message[String]]) => ...)

We have to provide a lot of more type-information to make this piece of code work.

Why get some methods 'WithHandler' appended to their original names?

After solving the original typing problem with currying, another problem popped up.

Let's take a look at the original code without appended WithHandler

  def send(address: String, message: AnyRef)
  def send[T](address: String, message: AnyRef)( replyHandler: io.vertx.core.AsyncResult [io.vertx.scala.core.eventbus.Message[T]] => Unit)

The Scala-compiler can't decide which method to pich when calling send("address", "hello world"). The only option here is to change the method name to avoid these overloading issues. Currying and method overloading simply don't play nice along and the rule of thumb is that you can have one or the other.

vertx-lang-scala's People

Contributors

larstimm avatar galderz avatar mchunkytrunk avatar vietj avatar

Watchers

Kevin avatar

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.