sbt / sbt-boilerplate

sbt plugin for generating scala.Tuple/Function related boilerplate code
BSD 2-Clause "Simplified" License
109 stars 19 forks source link

Support "skip ranges" #22

Closed dylemma closed 1 year ago

dylemma commented 7 years ago

This was motivated by my attempt to create a set of "combiner" classes, where each Combiner{N} had a method which returned a Combiner{N+1}.

[2..22#
class Combiner1[[#A1#]]([#v1: A1#]){
  def ~>[B](b: B) = new Combiner2[[#A1#], B]([#v1#], b)
  // plus a handful of actual methods
}
#
]

This won't compile because Combiner22#~> returns the non-existent Combiner23 class.

Rather than changing the loop to 2..21 and rewriting Combiner22 manually, you can now skip the ~> method for iteration 22 by wrapping it in [!22..# and #]:

[2..22#
class Combiner1[[#A1#]]([#v1: A1#]){
  [!22..#def ~>[B](b: B) = new Combiner2[[#A1#], B]([#v1#], b)#]
  // plus a handful of actual methods
}
#
]

Coincidentally, this can also be used to create comments in your templates

[#A1[!# Hello, template world!#]#]