Created
February 13, 2016 17:33
-
-
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").
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 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