Setting a variable one child above in an inline-function #2260
-
Below, I'm attempting to update the value of a variable(that is defined by it's parent) to a value(either the current length being evaluated, or the previous length) const usage = [
[ "-y", "Yes to all prompts" ],
[ "-r", "Recursive" ]
]
fn print_usage() {
let min_distance = 0
iterator.range(0, list.length(usage))
|> iterator.map(fn(i) {
let evaluation_distance =
string.length(result.unwrap(
list.at(result.unwrap(list.at(usage, i), [""]), 0),
"",
))
case evaluation_distance > min_distance {
True -> evaluation_distance
False -> min_distance
}
})
|> iterator.map(fn(val) {
min_distance = val # <- This says it needs to have "let" before it so that it can be defined... but it already is.
})
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I found my answer. I'm now using |
Beta Was this translation helpful? Give feedback.
-
Hey @Steve0Greatness ! You could make the code a little more concise using the Here's how I might write this: const usage = [
#("-y", "Yes to all prompts"),
#("-r", "Recursive"),
]
fn print_usage() {
let length =
usage
// Get the lengths of each description
|> list.map(fn(pair) { string.length(pair.1) })
// Find the longest one
|> list.fold(0, int.max)
} |
Beta Was this translation helpful? Give feedback.
I found my answer. I'm now using
gleam/javascript
's reference.