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

Function calls with trailing braced expressions #241

Open
DavisVaughan opened this issue Feb 18, 2025 · 0 comments
Open

Function calls with trailing braced expressions #241

DavisVaughan opened this issue Feb 18, 2025 · 0 comments

Comments

@DavisVaughan
Copy link
Member

Function calls where a braced expression is present in the last argument deserves a call out, as it is a special function call style (i.e. not exactly flat or expanded)

map(xs, function(x) {
  do_something(x)
})

map(xs, \(x) {
  do_something(x)
})

test_that("description", {
  test_me
})

These make for particularly unique function call layouts, because normally the expansion of the braced expression over multiple lines would force the expansion of every argument in the function call, looking like:

map(
  xs, 
  function(x) {
    do_something(x)
  }
)

map(
  xs, 
  \(x) {
    do_something(x)
  }
)

test_that(
  "description", 
  {
    test_me
  }
)

Note that this only applies to trailing braced expressions, for example with tryCatch() we do full expansion of every argument

tryCatch(
  {
    expr
  },
  error = function(e) {}
)
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

1 participant