0

What is the easiest way to generate ind many space? Any easier way other than using foldRight?

   (1 to ind).foldRight("") {
      case (_, a) => a + " "
   }
Daniel
  • 5,839
  • 9
  • 46
  • 85
  • What are you going to do next? Assuming this is for padding some more meaningful output, then `StringOps.format` or `f""` string interpolation along with your other output is probably more efficient? – The Archetypal Paul Feb 13 '16 at 18:03

1 Answers1

1

You could try this:

' '.toString * ind

Have a look at this, explaining the more generic case in detail: Efficiently repeat a character/string n times in Scala

Community
  • 1
  • 1
Dennis Hunziker
  • 1,293
  • 10
  • 19