Hello StackOverflow,
I have problems with writing an specific application in a scala-esque and elegant way. I tried this for some time now, but I cannot find a "good" solution to this Problem:
Given that I have the following List:
List("foo", "bar", "baz", "blah")
I want to Iterate over this list, not only giving me the current element for each Iteration but also the element before and after the current element. This might be a Tuple3 but is not required to. This could be the Tuple signature:
(Option[T], T, Option[T])
To clarify what i mean, this is the proposed Tuple for each iteration over a List[String]
, ending after the fourth.
Iteration 1: (None, "foo", Some("bar"))
Iteration 2: (Some("foo"), "bar", Some("baz"))
Iteration 3: (Some("bar"), "baz", Some("blah"))
Iteration 4: (Some("baz"), "blah", None)
How could I achieve such a result? Again: I am not bound to the Tuple3, any other solution is also very appreciated!
Thanks!