Convert single object to List
List<String> list = java.util.Arrays.asList("foo");
12364 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
List<String> list = java.util.Arrays.asList("foo");
Array.prototype.select = function(detect) { var result = []; for (var i = 0; i < this.length; ++i) { if (detect(this[i])) { result.push(this[i]); } } return result; }; Array.prototype.reject = function(detect) { var result = []; for (var i = 0; i < this.length; ++i) { if (!detect(this[i])) { result.push(this[i]); } } return result; }; Array.prototype.partition = function(detect) { var yeses = []; var nos = []; for (var i = 0; i < this.length; ++i) { if (detect(this[i])) { yeses.push(this[i]); } else { nos.push(this[i]); } } return [yeses, nos]; }; Array.prototype.all = function(detect) { for (var i = 0; i < this.length; ++i) { if (!detect(this[i])) { return false; } } return true; }; Array.prototype.any = function(detect) { for (var i = 0; i < this.length; ++i) { if (detect(this[i])) { return true; } } return false; }; Array.prototype.find = function(detect, ifNone) { for (var i = 0; i < this.length; ++i) { if (detect(this[i])) { return this[i]; } } if (ifNone === null) { return null; } return ifNone(); }; Array.prototype.map = function(mapper) { var result = []; for (var i = 0; i < this.length; ++i) { result.push(mapper(this[i])); } return result; }; Array.prototype.inject = function(initial, reducer) { var result = initial; for (var i = 0; i < this.length; ++i) { result = reducer(result, this[i]); } return result; };