Haskell in REPL:<p><pre><code> Prelude> :m Data.List
Prelude Data.List> let f xs = [(head ys, length ys) | ys <- group xs]
Prelude Data.List> f "aaaabbbcca"
[('a',4),('b',3),('c',2),('a',1)]
</code></pre>
Of course using the "group" function instead of programming it myself is cheating a bit ...
Surprising that F# doesn't have a "chunkBy" function for sequences; it makes the solution in Elixir vastly more readable than the version in the article:<p><pre><code> "aaaabbbcca" |> String.codepoints() |> Enum.chunk_by(& &1) |> Enum.map(&{hd(&1), length(&1)})</code></pre>
I did it this way:<p><pre><code> map (head &&& length) . group
</code></pre>
(Although in an actual full program, there would be other considerations (what considerations those are depends on the program being written), and in a full program I probably would not be using Haskell, but rather C.)
meanwhile python be out here like:<p><pre><code> [(m.group(1), len(m.group()))
for m in re.finditer(r"([a-z])\1*", “aaaabbbcca")</code></pre>