Re: Seq :+ repeat parameter
Dean Wampler <[email protected]> Thu, 7 Apr 2016 07:51:43 -0500
| Newsgroups | gmane.comp.lang.scala |
|---|---|
| Message-ID | <CAKW0i0zyWoL4MdDp=TCAqkgMcFVUSbifSj60MHJWAAWn_=JYLw@mail.gmail.com> |
Do you mean that you want to add the same object multiple times with a repeat parameter? That isn't provided, but a for loop would work. Or do you mean chaining? You can do the following: val scalaButs = CanvButton(...) +: CanvButton(...) +: ... +: Nil Note I used +: You don't want to use :+ with Lists (what Seq.apply() returns), because appending is O(n). However, appending to Vectors is O(1). val scalaButs1 = Vector(CanvButton(...)) val scalaButs = scalaButs1 :+ CanvButton(...) :+ ... :+ CanvButton(...) Dean Wampler, Ph.D. Author: Programming Scala, 2nd Edition <http://shop.oreilly.com/product/0636920033073.do> (O'Reilly) Lightbend <http://lightbend.com> @deanwampler <http://twitter.com/deanwampler> http://polyglotprogramming.com On Thu, Apr 7, 2016 at 7:45 AM, Rich Oliver <[email protected]> wrote: > I have created the following code and it seems to compile and run > correctly: > > val scaleButs = Seq(CanvButton("+", () => { scale = (scale * > 1.5).min(scaleMax); repaintMap() }), > CanvButton("-", () => { scale = (scale / 1.5).max(scaleMin); > repaintMap() })) > val mapButs = scaleButs :+ ( > CanvButton("<=", () => { mapFocus = mapFocus.subX(moveInc); > repaintMap() }), > CanvButton("=>", () => { mapFocus = mapFocus.addX(moveInc); > repaintMap() }), > CanvButton("Up", () => { mapFocus = mapFocus.addY(moveInc); > repaintMap() }), > CanvButton("down", () => { mapFocus = mapFocus.subY(moveInc); > repaintMap() }) > ) > > But in the API documentation the :+ doesn't have a repeat parameter. I've > looked in SeqLike.scala > https://github.com/scala/scala/blob/v2.11.8/src/library/scala/collection/SeqLike.scala#L1 > and I can't see any repeat parameter for the :+ method there either. > > -- > You received this message because you are subscribed to the Google Groups > "scala-language" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "scala-language" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.