scala - How to determine if a text occurs somewhere in the sequence? -


i'm suppose code if sequence streaming large file not fit in memory. can me on please? thank much!!

here's code:

def isyourtextinstream(stream: seq[string], text: string): boolean = {   if (text == null || text.length() == 0)     stream.empty  } 

i don't think seq[string] has memory profile necessary requirements you've outlined.

also, i'd avoid using "stream" variable/parameter name. stream has specific meaning in scala.

so anyway, here's solution i've come with. wanted without var wasn't clever enough.

def isyourtextinstream(stream: seq[string], text: string): boolean = {   if (text.isempty) return true   val input = stream.view.flatten.toiterator   var str = ""   while (input.hasnext && str != text) {     if (!str.isempty)       str = str.tail.dropwhile(_ != text.head)     if (str.isempty)       str = input.dropwhile(_ != text.head).take(text.length).mkstring     else       str += input.take(text.length - str.length).mkstring   }   str == text } 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -