-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c709d27
commit f9422b9
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
LiveScript | ||
# Easy listing of implicit objects | ||
table1 = | ||
* id: 1 | ||
name: 'george' | ||
* id: 2 | ||
name: 'mike' | ||
* id: 3 | ||
name: 'donald' | ||
|
||
table2 = | ||
* id: 2 | ||
age: 21 | ||
* id: 1 | ||
age: 20 | ||
* id: 3 | ||
age: 26 | ||
|
||
# Implicit access, accessignment | ||
up-case-name = (.name .= to-upper-case!) | ||
|
||
# List comprehensions, destructuring, piping | ||
[{id:id1, name, age} for {id:id1, name} in table1 | ||
for {id:id2, age} in table2 | ||
when id1 is id2] | ||
|> sort-by (.id) # using 'sort-by' from prelude.ls | ||
|> each up-case-name # using 'each' from prelude.ls | ||
|> JSON.stringify | ||
#=> | ||
#[{"id":1,"name":"GEORGE","age":20}, | ||
# {"id":2,"name":"MIKE", "age":21}, | ||
# {"id":3,"name":"DONALD","age":26}] | ||
|
||
# operators as functions, piping | ||
map (.age), table2 |> fold1 (+) | ||
#=> 67 ('fold1' and 'map' from prelude.ls) | ||
|
||
r = +...[4 5 6] #=> [+4, +5, +6] | ||
t = typeof! ...[\b 5 {}] #=> ["String", "Number", "Object"] | ||
c = ~...[4, 5] #=> [-5, -6] | ||
++...player<[strength hp]> | ||
# also works with -, --, typeof, ! and delete! | ||
i = new ...[some, classes] | ||
c = ^^...[copy, these, {}] | ||
delete ...list[1, 2, 3] | ||
do ...[a, b, c] |