I was reading the "Use sugar" section of the Gleam Language Tour, wherein a simplified example is provided of use
use a, b <- my_function
next(a)
next(b)
which expands to
my_function(fn(a, b) {
next(a)
next(b)
})
From my observation, it appears that the expansion is done, as follows:
aandbare arguments to the anonymous function- The body of the anonymous function has the lines
next(a)andnext(b) - Finally,
my_functionis called with the anonymous function as a callback.
On the code section of the screen, there's another example of use
let x = {
use username <- result.try(get_username())
use password <- result.try(get_password())
use greeting <- result.map(log_in(username, password))
greeting <> ", " <> username
}
However, I'm unclear how this is expanded. I'm not sure how I can apply the steps I observed in the first example to the second case.