Created
January 13, 2016 17:13
-
-
Save igl/4fb63b69dcb26a95838b to your computer and use it in GitHub Desktop.
livescript in a nutshell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# declarative code | |
function add1 n => n + 1 | |
function mul2 n => n * 2 | |
# pipes | |
alert( | |
1 | |
|> add1 | |
|> mul2 | |
) | |
# ...rest in the beginning | |
function doStuff (...args, cb) | |
[a, b, ...stuff] = args | |
cb void, a + b, stuff | |
# pattern matching | |
match 1 | |
| isNaN => "not a number" | |
| isFinite => "not infinity" | |
| otherwise => "something else" | |
# implicit first arg `it`, implicit switch-case as function body | |
matchNumbers = -> | |
| it is 0 => "zero" | |
| it is 1 => "one" | |
| it > 1 => "greater" | |
| _ => "smaller" | |
# backcalls against async madness | |
<- setTimeout _, 2000 | |
alert '2 Seconds later' | |
<- setTimeout _, 1000 | |
alert '3 Seconds later' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment