Skip to content

Instantly share code, notes, and snippets.

@igl

igl/ls.ls

Created Jan 13, 2016
Embed
What would you like to do?
livescript in a nutshell
# 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