sbt-boilerplate icon indicating copy to clipboard operation
sbt-boilerplate copied to clipboard

Support "skip ranges"

Open dylemma opened this issue 8 years ago • 0 comments

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!#]#]

dylemma avatar Dec 01 '16 22:12 dylemma