Skip to content

Instantly share code, notes, and snippets.

View gowrizrh's full-sized avatar

Gowri gowrizrh

View GitHub Profile
@gowrizrh
gowrizrh / main.exs
Last active October 22, 2024 23:10
Elixir Snippets
# binary pattern matching, return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
defmodule Main do
def str_str(haystack, needle) do
match(haystack, needle, 0)
end
def match(<<s, str::binary>>, <<s, needle::binary>>, index) do
needle_len = needle |> String.length()