Skip to content

Instantly share code, notes, and snippets.

@nkezhaya
Created May 9, 2021 17:10
Show Gist options
  • Select an option

  • Save nkezhaya/f63c3374cfddd2b5c251e6c83b671321 to your computer and use it in GitHub Desktop.

Select an option

Save nkezhaya/f63c3374cfddd2b5c251e6c83b671321 to your computer and use it in GitHub Desktop.
def copy_into(destination, src, destination_offset \\ 0, start_index \\ 0) do
destination = :binary.bin_to_list(destination)
{prefix, destination} = :lists.split(destination_offset, destination)
src = :binary.bin_to_list(src)
{_, src} = :lists.split(start_index, src)
{_replaced, destination} = :lists.split(length(src), destination)
:binary.list_to_bin(prefix ++ src ++ destination)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment