January 2019
Intermediate to advanced
246 pages
5h 23m
English
So far, types have mostly been about keeping our programs out of trouble. While that safety is useful, Crystal also offers many approaches so you can write code whose flow is determined by the types of data it’s processing. This simplifies the challenge of keeping code concise while accepting many different kinds of information.
Controlling the Flow showed you how to work with flow constructs, and you saw that a variable is never nil or false in the if-branch. Also, if you have an if var1 && var2, both var1 and var2 are guaranteed not to be nil. Those basics are useful, but Crystal offers many more possibilities.
Instead of using explicit ifs, you can use a more compact ternary form, as shown here:
| | var1 = ... |
Read now
Unlock full access