Scala - cycling over a finite sequence starting from a given element -


I need to cycle efficiently on a certain sequence, starting from any element, not always from the beginning.
The solution I am searching for is:

val directions = list ("north", "east", "south", "west") val cycle = stream. Continually (directions). Since I'm using it inside a hot loop, starting again and again, and the actual sequence is too long, I'm afraid dropWhile is going to spend a lot of me is.
Can I move it?
am I doing it right?

Edit

There were some good suggestions given that I should not use the stream s Now it is made: How can I use dropWhile or similar tasks?

Example below to prevent the listing of values ​​of the default sequences start each new stream escape from.

Package rando object faster app {val directions = Vector ("north", "east", "south", "west") val index = instructions. ZipWithIndex.map {case (d, i) = & gt; D -> I} .toMap def Stream WithStart (Start: String): Stream [String] = Direction Drape (Index (Start)). Stream (Ep. Continental (Directions) Flaton) Stream Wastart ("East") 10 Less (_ + "" + _) Front print; Println () Stream Vithart ("Answer") take less (_ + "+ +) foreach prints; Println () stream streams (" west ") 10 print less (_ +" + +) foreach; Println () stream streams ("south") take less (_ + "+ +) foreach print; Println ()}

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -