Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

216
Views
scala dos variables si otra condición

¿Cómo puedo hacer esto mejor en Scala?

 def fooOutput(v1: Double, v2: Int): Int = { if (v1 >= 9 & v2 >= 2) { 5 } else if (v1 >= 8) { 4 } else if (v1 >= 4) { 3 } else { 2 } }

No me gusta esto if else if else lógica.

¿Puedo usar la declaración de cambio para dos variables o tal vez algún mejor enfoque funcional de Scala?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Puede mover su condición a guardias de patrón, sin embargo, no está seguro de que sea mucho mejor:

 def fooOutput(v1: Double, v2: Int): Int = v1 match { case _ if v1 >= 9 && v2 >= 2 => 5 case _ if v1 >= 8 => 4 case _ if v1 >= 4 => 3 case _ => 2 }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!