Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

https://github.com/vlang-io/V/blob/master/examples/users.v

They are very simple and combine Rust's Option<T> and Result<T>.



  // `http.get()` returns an optional string.
  // V optionals combine the features of Rust's Option<T> and Result<T>.
  // We must unwrap all optionals with `or`, otherwise V will complain.
  s := http.get(API_URL) or {
  // `err` is a reserved variable (not a global) that
  // contains an error message if there is one
  eprintln('Failed to fetch "users.json": $err')
  // `or` blocks must end with `return`, `break`, or `continue`
  return
 }


This looks really handy. Is there somewhere else (outside of V) where I can read about Option types (in the real world, or in theory).


What's the difference between "break" and "continue" inside an or-block? Or do they apply to the outer enclosing loop if there is one?


Yes, just like in Swift.


Then I don't get it - how do you make the or-block exit normally and yield a value, instead of exiting the outer scope one way or another?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: