-
Notifications
You must be signed in to change notification settings - Fork 3
Single
Yasser Moradi edited this page Aug 26, 2015
·
2 revisions
Description:
This method returns single item. When you expect sequence contains one item . If sequence has more than one element or is empty the method throws an exception.
Sample:
let items = ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten'];
let singleList = ['one'];
let single = singleList.asEnumerable().single();
console.log(single);
try {
single = empty.asEnumerable().single();
}
catch (err) {
console.error(err.message);
}
single = items.asEnumerable().single(item => item.indexOf('O') === 0);
try {
single = items.asEnumerable().single(item => item.indexOf('F') === 0);
}
catch (err) {
console.error(err.message);
}