Expanding the function capture syntax to work for arbitrary expressions #3433
Replies: 3 comments 10 replies
-
Hello! Thanks for the suggestion. What's the rationale for this change? I would write the above like so today: // Currently
let num =
[1, 2, 3, 4, 5, 6]
|> list.filter(int.is_odd)
|> list.map(fn(it) { it * 2 + 1 })
|> int.sum
io.debug(num % 10) This is more concise then either example, and I think maybe clearer too. Technical detailsHow would the compiler know how far up the syntax tree to ascend to get all the code that should go in the function? You seem to be using two different approaches in your example. |
Beta Was this translation helpful? Give feedback.
-
Just to add my 2-cents, I wish there was a nicer way with nested calls. Sometimes I have to wrap my functions: pub fn init() -> Effect(msg.Msg) {
let msg = fn(x) { msg.AuthMsg(msg.OAuthServerStarted(x)) }
tauri.invoke("start_server", [], tauri.expect_json(zero.int, msg))
} But I would find it prettier if I could just: pub fn init() -> Effect(msg.Msg) {
let msg = _ |> msg.OAuthServerStarted |> msg.AuthMsg
tauri.invoke("start_server", [], tauri.expect_json(zero.int, msg))
} Or if there was some func comp thing like haskell that im not aware of |
Beta Was this translation helpful? Give feedback.
-
All these example feels like a short hand function definition. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Using the function capture syntactic sugar is a great tool, I'd like for that tool to be usable in more places. For example in arithmetic, equality operations, and as the initial value of a pipe.
Beta Was this translation helpful? Give feedback.
All reactions