Thanks Sean! On Fri, Oct 24, 2014 at 3:04 PM, Sean Owen <so...@cloudera.com> wrote:
> This is just a Scala question really. Use ++ > > def inc(x:Int, y:Int) = { > if (condition) { > for(i <- 0 to 7) yield(x, y+i) > } else { > (for(k <- 0 to 24-y) yield(x, y+k)) ++ (for(j<- 0 to y-16) > yield(x+1,j)) > } > } > > On Fri, Oct 24, 2014 at 8:52 PM, HARIPRIYA AYYALASOMAYAJULA > <aharipriy...@gmail.com> wrote: > > Hello, > > > > My map function will call the following function (inc) which should yield > > multiple values: > > > > > > def inc(x:Int, y:Int) > > ={ > > if(condition) > > { > > for(i <- 0 to 7) yield(x, y+i) > > } > > > > else > > { > > for(k <- 0 to 24-y) yield(x, y+k) > > for(j<- 0 to y-16) yield(x+1,j) > > > > } > > } > > > > The "if" part works fine, but in the else part , if should return 2 > sets of > > values (from the first for loop and then from the second for loop). But, > > only the values from second for loop (within else) are returned by the > > function. > > > > I tried alternative ways but I am unable to make the above function give > me > > the expected result. > > > > Can someone help me understand how yield works, and what should be used > in > > place of yield to return multiple values when two for loops have to be > > used.(like the test case in within else condition) - If it was in JAVA > or > > C, we could simply store the values in an array or a list and return the > > same but I'm still not clear how it works in Scala/Spark. > > > > Thank you for your time. > > > > -- > > Regards, > > Haripriya Ayyalasomayajula > > Graduate Student > > Department of Computer Science > > University of Houston > > Contact : 650-796-7112 > -- Regards, Haripriya Ayyalasomayajula Graduate Student Department of Computer Science University of Houston Contact : 650-796-7112