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

Event-listener setters should have signature onClick[U](f: View ⇒ U) instead of onClick(f: View ⇒ Unit) #78

Closed
nadavwr opened this issue Feb 28, 2014 · 1 comment

Comments

@nadavwr
Copy link

nadavwr commented Feb 28, 2014

I find myself adding superfluous unit literals at the end of event handlers.

Compare the following two examples:

Using Scaloid's onClick:

button.onClick {
  dir.mkdir() // ← returns Boolean, not Unit
  () // ← boilerplate required to conform with Unit result type
}

Compared to trivial usage of Scala's foreach:

dirs.foreach { dir ⇒
  dir.mkdir() // ← returns Boolean, which is discarded
}

The latter is preferable.

This is really easy to implement, as seen from foreach's definition:

def foreach[U](f: A ⇒ U): Unit

Where U clearly stands for Unit, but is actually more liberal.

Applying this to (e.g.) 'onClick', the signature would look like so:

def onClick[U](f: View ⇒ U)
@pocorall
Copy link
Owner

Good suggestion, thanks!
I am working on this issue.

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

No branches or pull requests

2 participants