-1

I have a the following Java snippet (where a and b are futures):

if (a.isEmpty && b.isEmpty) func(list)
else if (a.isEmpty) func(list, b)
else if (b.isEmpty) func(a, list)
else func(a, list, b)

I have all the implementations of the function 'func'. Is there a proper way to write this in Scala or is this good enough?

Simon Hughes
  • 3,534
  • 3
  • 24
  • 45
NPK
  • 123
  • 1
  • 9

1 Answers1

1

Assuming a and b are lists, which seems likely as they seem related to list:

(a, b) match {
  case (Nil, Nil) => func(list)
  case (Nil, _)   => func(list, b)
  case (_, Nil)   => func(a, list)
  case _          => func(a, b, list)
}
The Archetypal Paul
  • 41,321
  • 20
  • 104
  • 134