Skip to content

Commit

Permalink
Add Agg.when operator (#2535)
Browse files Browse the repository at this point in the history
This is a super common operation to want in the builds i've come across:
conditional scalac flags, conditional deps, conditional sources, etc.
Better to have it built in as `Agg.when(foo)("bar", "baz")` rather than
jumping through hoops with `++ (if (foo) Agg("bar", "baz") else
Agg.empty)`
  • Loading branch information
lihaoyi authored May 20, 2023
1 parent 73437ce commit b8178b2
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions main/api/src/mill/api/AggWrapper.scala
Original file line number Diff line number Diff line change
@@ -155,5 +155,13 @@ private[mill] sealed class AggWrapper(strictUniqueness: Boolean) {
}

override def newBuilder[A]: mutable.Builder[A, Agg[A]] = Mutable.newBuilder[A]

/**
* Similar to [[Agg.apply]], but with a conditional boolean that makes it
* return `Agg.empty` if `false`.
*/
def when[A](cond: Boolean)(items: A*): Agg[A] = {
if (cond) Agg.from(items) else Agg.empty
}
}
}

0 comments on commit b8178b2

Please # to comment.