July 2018
Intermediate to advanced
400 pages
12h 14m
English
with is a variant of run. It behaves identically, but it uses a different calling convention. Unlike the standard functions you have seen so far, with requires its argument to be accepted as the first parameter rather than calling the standard function on a receiver type:
val nameTooLong = with("Polarcubis, Supreme Master of NyetHack") {
length >= 20
}
Instead of calling with on the string, as in "Polarcubis, Supreme Master of NyetHack".run, the string is passed as the first (in this case, only) argument to with.
This is inconsistent with the way you work with the rest of the standard functions, making it a less favorable choice than run. In fact, we recommend avoiding with and using run instead. We are including with
Read now
Unlock full access