Skip to content

Commit 8989640

Browse files
committed
.
1 parent cba7e7c commit 8989640

File tree

4 files changed

+33
-19
lines changed

4 files changed

+33
-19
lines changed

core/api/src/mill/api/opt/Opt.scala

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
package mill.api.opt
22

33
import mill.api.daemon.internal.OptApi
4-
54
import mill.api.JsonFormatters.given
65

76
import scala.annotation.targetName
7+
import scala.language.implicitConversions
88

9-
type OptTypes = (String | os.Path)
10-
11-
case class Opt private (value: Seq[OptTypes]) extends OptApi {
9+
case class Opt private (value: Seq[Opt.OptTypes]) extends OptApi {
1210
override def toString(): String = value.mkString("")
1311

14-
def map(conv: OptTypes => OptTypes): Opt = Opt(value.map(conv)*)
12+
def map(conv: Opt.OptTypes => Opt.OptTypes): Opt = Opt(value.map(conv)*)
1513

1614
private def startStrings: Seq[String] =
1715
value.takeWhile(_.isInstanceOf[String]).collect { case s: String => s }
@@ -30,6 +28,9 @@ case class Opt private (value: Seq[OptTypes]) extends OptApi {
3028
}
3129

3230
object Opt {
31+
32+
type OptTypes = (String | os.Path)
33+
3334
@targetName("applyVarArg")
3435
def apply(value: OptTypes*): Opt = {
3536
// TODO: merge sequential strings
@@ -76,6 +77,17 @@ object Opt {
7677
}*)
7778
)
7879

79-
given stringToOpt: Conversion[String, Opt] = (value: String) => Opt(value)
80-
given osPathToOpt: Conversion[os.Path, Opt] = (value: os.Path) => Opt(value)
80+
// given stringToOpt: Conversion[String, Opt] = (value: String) => Opt(value)
81+
// given osPathToOpt: Conversion[os.Path, Opt] = (value: os.Path) => Opt(value)
82+
83+
// implicit def IterableToOpt[T](s: Iterable[T])(using f: T => Opt): Opt =
84+
// Opt(s.toSeq.flatMap(f(_).value))
85+
86+
87+
implicit def StringToOpt(s: String): Opt = Opt(s)
88+
89+
implicit def OsPathToOpt(p: os.Path): Opt = Opt(p)
90+
91+
implicit def OptToOpt(o: Opt): Opt = o
92+
8193
}

core/api/src/mill/api/opt/OptGroup.scala

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,19 @@ case class OptGroup private (value: Seq[Opt]) extends OptGroupApi
1818

1919
def head: Opt = value.head
2020

21-
def toStringSeq: Seq[String] = value.map(_.toString)
21+
def toStringSeq: Seq[String] = value.map(_.toString())
22+
23+
def concat(suffix: OptGroup): OptGroup = new OptGroup(value ++ suffix.value)
24+
25+
@`inline` final def ++(suffix: OptGroup): OptGroup = concat(suffix)
26+
2227
}
2328

2429
object OptGroup {
25-
@targetName("applyUnion")
26-
def apply(value: (Opt | Seq[Opt])*): OptGroup = new OptGroup(value.flatMap {
27-
case a: Opt => Seq(a)
28-
case s: Seq[Opt] => s
29-
})
30+
@targetName("applyVarAar")
31+
def apply(opts: Opt*): OptGroup = new OptGroup(opts)
32+
@targetName("applyIterable")
33+
def apply[T](opts: T*)(using f: T => Opt): OptGroup = new OptGroup(opts.map(f(_)))
3034

3135
def when(cond: Boolean)(value: Opt*): OptGroup = if (cond) OptGroup(value*) else OptGroup()
3236

@@ -43,7 +47,8 @@ object OptGroup {
4347
implicit def IterableToOptGroup[T](s: Iterable[T])(using f: T => OptGroup): OptGroup =
4448
OptGroup(s.toSeq.flatMap(f(_).value))
4549

46-
implicit def ArrayToOptGroup[T](s: Array[T])(using f: T => OptGroup): OptGroup =
47-
OptGroup(s.flatMap(f(_).value))
50+
// implicit def ArrayToOptGroup[T](s: Array[T])(using f: T => OptGroup): OptGroup =
51+
// OptGroup(s.flatMap(f(_).value))
52+
4853

4954
}

core/api/src/mill/api/opt/OptSyntax.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package mill.api.opt
22

3-
import mill.api.daemon.internal.{OptApi, OptGroupApi, OptsApi}
4-
5-
import scala.annotation.targetName
63
import scala.language.implicitConversions
74

85
implicit class OptSyntax(ctx: StringContext) extends AnyVal {

core/api/src/mill/api/opt/Opts.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import scala.language.implicitConversions
77
case class Opts private (override val value: OptGroup*) extends OptsApi
88
derives upickle.ReadWriter {
99

10-
def toStringSeq: Seq[String] = value.map(_.toString)
10+
def toStringSeq: Seq[String] = value.flatMap(_.toStringSeq)
1111
override def toString(): String = value.mkString("Opts(", ", ", ")")
1212

1313
def concat(suffix: Opts): Opts = Opts(value ++ suffix.value)

0 commit comments

Comments
 (0)