0

I have a list of Tuple(s) like:

val rez = List((A, B, C, D, E, WrappedArray(F1, F2, F3)), (A2, B2, C2, D2, E2, WrappedArray(F4, F5)))

What I am trying to do is to create a string from each tuple in the list, so that (e.g., for the first tuple):

if(C == "Bob") then "A => (F1 \/ F2 \/ F3)"

The elements in the Tuple are, of course, of different types (in the WrappedArray() are of the same type).

My difficult part is how to make the string like (F1 \/ F2 \/ F3) from the elements within the WrappedArray()?

Thanks for any help.

2
  • the second element in the list has a WrappedArray of only two elements (F4, F5).. how should it be handled? Commented Feb 23, 2017 at 16:32
  • @rogue-one, it should become like (F4 \/ F5), as the WrappedArray in my case has a different number of elements. Commented Feb 23, 2017 at 16:37

1 Answer 1

2

If I understand your requirement correctly.. the below should work..

val rez = List(("A", "B", "Bob", "D", "E", Array("F1", "F2", "F3")), ("A2", "B2", "Bob", "D2", "E2", Array("F4", "F5")))

val result = rez map {
 case (a, b, c, d, e, array) if(c == "Bob") => s"$a => ${array.mkString(" \\/ ")}"
}
result: List[String] = List(A => F1 \/ F2 \/ F3, A2 => F4 \/ F5)
Sign up to request clarification or add additional context in comments.

1 Comment

"Yes, Sir!" It's really working. I tried so much, in different ways :(. Thank you so much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.