Sha256: 7c3e78e4dbf1ca1d872ecede711c141fb566d581ee4174ad85badb4f51ea7faf
Contents?: true
Size: 443 Bytes
Versions: 226
Compression:
Stored size: 443 Bytes
Contents
defmodule StringSeries do @doc """ Given a string `s` and a positive integer `size`, return all substrings of that size. If `size` is greater than the length of `s`, or less than 1, return an empty list. """ @spec slices(s :: String.t(), size :: integer) :: list(String.t()) def slices(_s, size) when size < 1, do: [] def slices(s, size) do s |> String.graphemes |> Enum.chunk(size, 1) |> Enum.map(&Enum.join/1) end end
Version data entries
226 entries across 226 versions & 1 rubygems