Hacker News new | past | comments | ask | show | jobs | submit login

Can you also please explain what the "||" is doing? That looks really weird to me coming from Swift and don't see it in the docs.

edit: thanks all, should have known it was a lambda :D, in Swift we can omit this. My first thought seeing "||" was some type of OR logic since it's in the context of if/else




Rust lambdas look like this:

    |ar,gs| expr
So `|| expr` is just a lambda function that takes no arguments and evaluates to `expr`.


It is a lambda function with no parameters.

The argument of then() is a function which is evaluated only if the bool is true.


empty parameter list of a closure.

rust: |x| x+x

swift: {x in x+x}

rust: || 42

swift: { 42 }




Join us for AI Startup School this June 16-17 in San Francisco!

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

Search: