#Am I thinking about ingesting numeric input from the CLI at all correctly?
1 messages · Page 1 of 1 (latest)
Is zero a reasonable default in this case?
Let's say yes.
"Enter a number:\n"
|> erlang.get_line
|> result.nil_error
|> result.map(with: string.trim)
|> result.try(apply: int.parse)
|> result.unwrap(or: 0)
|> io.debug
You could also use case and pattern matching instead.
My understanding is w/ pattern matching strings I'd need to reverse it to ignore the n\ from the newline before I could match.
Becomes just as gross. 🤷♂️
Might just be needfully gnarly.
Thanks for the suggestions!
I meant pattern matching the Result, not the string.
Interesting.
So, in my mind the thing that feels off is the number of steps to get to a properly parsed int.
I'm sensing that in yours it's the stepwise processing w/o the safety of results. That a fair characterization?
Not sure. I don't like doing a bunch of unwraps and repetitive stuff like that.