.NET's LINQ contains an operator .Single which
Returns the only element of a sequence, and throws an exception if there is not exactly one element in the sequence.
Is there an equivalent in the latest version of JavaScript? (ECMA v8 at time of writing).
The closest operation that I could find was .find though one would have to write their own boilerplate to assert that exactly one elemet matched.
Example of expected functionality of .single():
const arr = [1, 4, 9];
arr.single(v => v > 8 && v < 10); // Returns 9
arr.single(v => v < 5); // Throws an exception since more than one matches
arr.single(v => v > 10); // Throws an exception since there are zero matches