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
# 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() |