Skip to content

Instantly share code, notes, and snippets.

@RomanKotov
RomanKotov / consecutive_ranges.exs
Last active March 17, 2024 17:21
Compare different_approaches to build ranges of consecutive items https://x.com/chgeuer/status/1768027992691781757
Mix.install([
{:benchee, "~> 1.3"}
])
defmodule TailRecursive do
defstruct from: nil, to: nil
def identify([], _), do: []
def identify([item], _), do: %__MODULE__{from: item, to: item}
def identify(v, is_next) when is_list(v) do