Skip to content

Instantly share code, notes, and snippets.

@vysakh0
Created February 13, 2016 17:33
Show Gist options
  • Save vysakh0/336120925bc2827e92f5 to your computer and use it in GitHub Desktop.
Save vysakh0/336120925bc2827e92f5 to your computer and use it in GitHub Desktop.
if the stream is "aaaafoo" and the word to search for is "foo", the function should print "Found foo" on the 6th incoming char (the last 'o' in "foo").
defmodule Foo do
def find(word) do
find(IO.getn(""), word, word)
end
def find(_char, "", word) do
IO.puts "Found #{word}"
end
def find(char, << char :: binary-size(1), rest :: binary >>, word) do
find(IO.getn(""), rest, word)
end
def find(_char, part, word) do
find(IO.getn(""), part, word)
end
end
Foo.find("foo")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment