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

Projects
None yet
2 participants
@nadavwr

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

This comment has been minimized.

Show comment
Hide comment
@pocorall

pocorall Mar 23, 2014

Owner

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

Owner

pocorall commented Mar 23, 2014

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

@pocorall pocorall closed this in 7a8f702 Mar 23, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment