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

Allow trailing function as last parameter #17

Open
MatheusRich opened this issue Jun 11, 2021 · 2 comments
Open

Allow trailing function as last parameter #17

MatheusRich opened this issue Jun 11, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@MatheusRich
Copy link
Collaborator

MatheusRich commented Jun 11, 2021

fn on_click { |btn, callback|
  # run the callback when the button is clicked
} 

on_click(my_btn) { puts("clicked!") }


fn map { |array, f|
  # for each element in array, apply f
}

map([1, 2, 3]) { |element| element * 2 }
@MatheusRich MatheusRich added the enhancement New feature or request label Jun 11, 2021
@MatheusRich
Copy link
Collaborator Author

MatheusRich commented Jun 14, 2021

Swift actually lets you pass multiple lambdas to methods.

func loadPicture(from server: Server, completion: (Picture) -> Void, onFailure: () -> Void) {
    if let picture = download("photo.jpg", from: server) {
        completion(picture)
    } else {
        onFailure()
    }
}

loadPicture(from: someServer) { picture in
    someView.currentPicture = picture
} onFailure: {
    print("Couldn't download the next picture.")
}

Elixir does something similar.

@MatheusRich
Copy link
Collaborator Author

Lots of good ideas in Kotlin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant