Skip to content

Instantly share code, notes, and snippets.

@fogus
Last active December 16, 2015 01:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fogus/5354028 to your computer and use it in GitHub Desktop.
Save fogus/5354028 to your computer and use it in GitHub Desktop.
var S = ['a', 'a', 'a', 'a', 'b', 'c', 'c', 'a', 'a', 'd', 'e', 'e', 'e', 'e'];
var pack = L.partial1(L.partitionBy, _.identity);
pack(S);
//=> [['a', 'a', 'a', 'a'],['b'],['c', 'c'],['a', 'a'],['d'],['e', 'e', 'e', 'e']]
var rle = _.compose(
L.partial1(L.flip(_.map),
L.juxt(L.plucker('length'), _.first)),
pack);
rle(S);
//=> [[4, 'a'], [1, 'b'], [2, 'c'], [2, 'a'], [1, 'd'], [4, 'e']]
var rld = _.compose(_.flatten, L.partial1(L.flip(_.map), L.splat(L.repeat)));
L.pipeline(S, rle, rld);
//=> ["a", "a", "a", "a", "b", "c", "c", "a", "a", "d", "e", "e", "e", "e"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment