Skip to content

bishabosha/enhanced-string-interpolator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

enhanced-string-interpolator

CI status javadoc

An enhanced glob interpolator for Scala with format strings

read full usage in the documentation, or the original inspiration in my blog post

Note that JDK 17+ is required

Basic usage

import stringmatching.regex.Interpolators.r

"[23, 56, 71]" match
  case r"[${r"$xs%d"}...(, )]" => xs.sum // 150

Below is a table of all the useful format strings:

Format Binding Note
$foo foo: String
$foo%d foo: Int
$foo%L foo: Long
$foo%f foo: Float
$foo%g foo: Double
$foo...(<regex>) foo: Seq[String] split by regex
$foo..!(<regex>) foo: Seq[String] drops first if empty
${r"$foo%d"}...(<regex>) foo: Seq[Int] match on each element
${r"$foo%L"}...(<regex>) foo: Seq[Long] match on each element
${r"$foo%f"}...(<regex>) foo: Seq[Float] match on each element
${r"$foo%g"}...(<regex>) foo: Seq[Double] match on each element

About

An enhanced glob interpolator for Scala with format strings

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages