Split a character string based on change of character: Difference between revisions
Split a character string based on change of character (view source)
Revision as of 06:57, 14 October 2021
, 2 years ago→JS ES6
m (→JS ES6) |
m (→JS ES6) |
||
Line 1,251:
// elements equal under (===), such that the
// concatenation of these lists is xs.
// groupBy :: (a -> a -> Bool) [a] -> [[a]]
const groupBy = eqOp =>
// A list of lists, each containing only elements
// equal under the given equality operator,
// such that the concatenation of these lists is xs.
xs => 0 < xs.length ? (() => {
const [h, ...t] = xs;
const [v, r] = t.reduce(
([
Tuple(
) : Tuple([...
Tuple([])([h])
);
Line 1,262 ⟶ 1,270:
return [...v, r];
})() : [];
// Tuple (,) :: a -> b -> (a, b)
|