windymelt / qw.scala   0.1.5

BSD 3-clause "New" or "Revised" License GitHub

Scala porting for qw() from Perl

Scala versions: 3.x

qw.scala CI qw Scala version support scaladoc

This library ports qw() syntax from Perl.

You can save time from double quotation hell when coding long String list.

Usage

Usage is very simple!

Dependency

Check out latest version → qw Scala version support

// for sbt
val qwVersion = "0.1.5"
libraryDependencies += "io.github.windymelt" %% "qw" % qwVersion

// for Mill
ivy"io.github.windymelt::qw:0.1.5"

// for Scala CLI
//> using dep "io.github.windymelt::qw:0.1.5"

Basic usage

Instead of writing List[String](...) directly, you can express it writing space-separated string:

import io.github.windymelt.qw.Syntax.{*, given}

val lis: List[String] = qw"You can save time from double-quotation hell"
// => List("You", "can", "save", "time", "from", "double-quotation", "hell")

You can express list via multi-line:

val lis = qw"""
a b
c d
e f
"""
// => List("a", "b", "c", "d", "e", "f")

Advanced usage

You can embed String variable into notation:

import io.github.windymelt.qw.Syntax.{*, given}

val (x, y, z) = ("a", "b", "c")

val lis: List[String] = qw"$a $b $c" // => List("a", "b", "c")
val lis2: List[String] = qw"$a$b$c"  // => List("a", "b", "c")