Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
catnaroek
on Sept 19, 2016
|
parent
|
context
|
favorite
| on:
My experience rewriting Enjarify in Rust
You can convert an `Option` into a `Result` and then use the `try!` macro, all in a single line:
http://stackoverflow.com/a/37890739/46571
glandium
on Sept 19, 2016
[–]
But Iterator's next() returns an Option, not a Result.
catnaroek
on Sept 19, 2016
|
parent
[–]
I don't see why you'd want to manipulate iterators by hand, unless you're implementing custom iterators. But, in any case:
try!(iter.next().ok_or("end of sequence"))
EDIT: Sorry. I was just being dense.
glandium
on Sept 19, 2016
|
root
|
parent
[–]
Check out the code that goes along the "no try! for Option" comment in the OP: it
is
implementing a custom iterator.
catnaroek
on Sept 19, 2016
|
root
|
parent
[–]
Oh, my bad. I guess `try!` isn't a good enough replacement for properly treating `Option` and `Result` as monads.
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search: