Last active
March 14, 2024 18:02
-
-
Save JamesTheAwesomeDude/f593ecbfb53fc416296ebb1a0fd7b85b to your computer and use it in GitHub Desktop.
Elixir lazy iterate over byte string (aka "binary" type)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule BitStringStream do | |
def binary_to_stream(s) do | |
Stream.unfold(s, fn | |
<<next::8, rem::binary>> -> {next, rem} | |
<<>> -> nil | |
end) | |
end | |
def bitstring_to_stream(s, n) do | |
Stream.unfold(s, fn | |
<<next::bitstring-size(n), rem::bitstring>> -> {next, rem} | |
<<>> -> nil | |
end) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment