Skip to content

sakano/linq.tjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 

Repository files navigation

linq.tjs

LINQ for TJS

Documentation

Example

var data = [
    %[ name:"United States",  GDP:17348072 ],
    %[ name:"China",          GDP:10430590 ],
    %[ name:"Japan",          GDP:4605511 ],
    %[ name:"Germany",        GDP:3868291 ],
    %[ name:"United Kingdom", GDP:2988893 ],
    %[ name:"France",         GDP:2829192 ],
    %[ name:"Brazil",         GDP:2346523 ],
    %[ name:"India",          GDP:2054941 ]
];

// print countries' name whose GDP is greater than 3000000
Enumerable.from(data)
    .where(function(x) { return x.GDP > 3000000; })
    .select(function(x) { return x.name; })
    .forEach(function(name) { Debug.message("name: " + name); });

// Above code will output :
//   name: United States
//   name: China
//   name: Japan
//   name: Germany

// string can be used as function expression
// '_' means the first argument
// the following code will output same messages
Enumerable.from(data)
    .where("_.GDP > 3000000")
    .select("_.name")
    .forEach("Debug.message('name: ' + _)");