Skip to content

Commit fa84fe7

Browse files
committed
Rewrite library to indent
1 parent 0ebb797 commit fa84fe7

26 files changed

+380
-751
lines changed

library/src-bootstrapped/scala/runtime/TupledFunctions.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import scala.util.TupledFunction
44
import scala.annotation.experimental
55

66
@experimental
7-
object TupledFunctions {
7+
object TupledFunctions:
88

99
def tupledFunction0[F, G]: TupledFunction[F, G] = TupledFunction[F, G](
1010
tupledImpl = (f: F) => ((args: EmptyTuple) => f.asInstanceOf[() => Any].apply()).asInstanceOf[G],
@@ -162,4 +162,3 @@ object TupledFunctions {
162162
}.asInstanceOf[F]
163163
)
164164

165-
}

library/src/scala/CanEqual.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ sealed trait CanEqual[-L, -R]
1111
* CanEqual instances involving primitive types or the Null type are handled directly in
1212
* the compiler (see Implicits.synthesizedCanEqual), so they are not included here.
1313
*/
14-
object CanEqual {
14+
object CanEqual:
1515
/** A universal `CanEqual` instance. */
1616
object derived extends CanEqual[Any, Any]
1717

@@ -44,4 +44,3 @@ object CanEqual {
4444
given canEqualEither[L1, R1, L2, R2](
4545
using eqL: CanEqual[L1, L2], eqR: CanEqual[R1, R2]
4646
): CanEqual[Either[L1, R1], Either[L2, R2]] = derived
47-
}

library/src/scala/IArray.scala

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ object IArray:
606606
* @param ys an array of AnyRef
607607
* @return true if corresponding elements are equal
608608
*/
609-
def equals(xs: IArray[AnyRef], ys: IArray[AnyRef]): Boolean =
609+
def equals(xs: IArray[AnyRef], ys: IArray[AnyRef]): Boolean =
610610
Array.equals(xs.asInstanceOf[Array[AnyRef]], ys.asInstanceOf[Array[AnyRef]])
611611

612612
/** Returns a decomposition of the array into a sequence. This supports
@@ -624,15 +624,13 @@ object IArray:
624624
/** Apply `f` to each element for its side effects.
625625
* Note: [U] parameter needed to help scalac's type inference.
626626
*/
627-
def foreach[U](f: T => U): Unit = {
627+
def foreach[U](f: T => U): Unit =
628628
val len = xs.length
629629
var i = 0
630-
while(i < len) {
630+
while(i < len)
631631
val x = xs(i)
632632
if(p(x)) f(x)
633633
i += 1
634-
}
635-
}
636634

637635
/** Builds a new array by applying a function to all elements of this array.
638636
*
@@ -641,16 +639,14 @@ object IArray:
641639
* @return a new array resulting from applying the given function
642640
* `f` to each element of this array and collecting the results.
643641
*/
644-
def map[U: ClassTag](f: T => U): IArray[U] = {
642+
def map[U: ClassTag](f: T => U): IArray[U] =
645643
val b = IArray.newBuilder[U]
646644
var i = 0
647-
while (i < xs.length) {
645+
while (i < xs.length)
648646
val x = xs(i)
649647
if(p(x)) b += f(x)
650648
i = i + 1
651-
}
652649
b.result()
653-
}
654650

655651
/** Builds a new array by applying a function to all elements of this array
656652
* and using the elements of the resulting collections.
@@ -660,16 +656,14 @@ object IArray:
660656
* @return a new array resulting from applying the given collection-valued function
661657
* `f` to each element of this array and concatenating the results.
662658
*/
663-
def flatMap[U: ClassTag](f: T => IterableOnce[U]): IArray[U] = {
659+
def flatMap[U: ClassTag](f: T => IterableOnce[U]): IArray[U] =
664660
val b = IArray.newBuilder[U]
665661
var i = 0
666-
while(i < xs.length) {
662+
while(i < xs.length)
667663
val x = xs(i)
668664
if(p(x)) b ++= f(xs(i))
669665
i += 1
670-
}
671666
b.result()
672-
}
673667

674668
def flatMap[BS, U](f: T => BS)(using asIterable: BS => Iterable[U], m: ClassTag[U]): IArray[U] =
675669
flatMap[U](x => asIterable(f(x)))

library/src/scala/Tuple.scala

Lines changed: 34 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import compiletime._
55
import compiletime.ops.int._
66

77
/** Tuple of arbitrary arity */
8-
sealed trait Tuple extends Product {
8+
sealed trait Tuple extends Product:
99
import Tuple._
1010

1111
/** Create a copy of this tuple as an Array */
@@ -78,76 +78,64 @@ sealed trait Tuple extends Product {
7878
*/
7979
inline def splitAt[This >: this.type <: Tuple](n: Int): Split[This, n.type] =
8080
runtime.Tuples.splitAt(this, n).asInstanceOf[Split[This, n.type]]
81-
}
8281

83-
object Tuple {
82+
object Tuple:
8483

8584
/** Type of a tuple with an element appended */
86-
type Append[X <: Tuple, Y] <: NonEmptyTuple = X match {
85+
type Append[X <: Tuple, Y] <: NonEmptyTuple = X match
8786
case EmptyTuple => Y *: EmptyTuple
8887
case x *: xs => x *: Append[xs, Y]
89-
}
9088

9189
/** Type of the head of a tuple */
92-
type Head[X <: NonEmptyTuple] = X match {
90+
type Head[X <: NonEmptyTuple] = X match
9391
case x *: _ => x
94-
}
9592

9693
/** Type of the initial part of the tuple without its last element */
97-
type Init[X <: Tuple] <: Tuple = X match {
94+
type Init[X <: Tuple] <: Tuple = X match
9895
case _ *: EmptyTuple => EmptyTuple
9996
case x *: xs =>
10097
x *: Init[xs]
101-
}
10298

10399
/** Type of the tail of a tuple */
104-
type Tail[X <: NonEmptyTuple] <: Tuple = X match {
100+
type Tail[X <: NonEmptyTuple] <: Tuple = X match
105101
case _ *: xs => xs
106-
}
107102

108103
/** Type of the last element of a tuple */
109-
type Last[X <: Tuple] = X match {
104+
type Last[X <: Tuple] = X match
110105
case x *: EmptyTuple => x
111106
case _ *: xs => Last[xs]
112-
}
113107

114108
/** Type of the concatenation of two tuples */
115-
type Concat[X <: Tuple, +Y <: Tuple] <: Tuple = X match {
109+
type Concat[X <: Tuple, +Y <: Tuple] <: Tuple = X match
116110
case EmptyTuple => Y
117111
case x1 *: xs1 => x1 *: Concat[xs1, Y]
118-
}
119112

120113
/** Type of the element at position N in the tuple X */
121-
type Elem[X <: Tuple, N <: Int] = X match {
114+
type Elem[X <: Tuple, N <: Int] = X match
122115
case x *: xs =>
123-
N match {
116+
N match
124117
case 0 => x
125118
case S[n1] => Elem[xs, n1]
126-
}
127-
}
128119

129120
/** Literal constant Int size of a tuple */
130-
type Size[X <: Tuple] <: Int = X match {
121+
type Size[X <: Tuple] <: Int = X match
131122
case EmptyTuple => 0
132123
case x *: xs => S[Size[xs]]
133-
}
134124

135125
/** Fold a tuple `(T1, ..., Tn)` into `F[T1, F[... F[Tn, Z]...]]]` */
136126
type Fold[Tup <: Tuple, Z, F[_, _]] = Tup match
137127
case EmptyTuple => Z
138128
case h *: t => F[h, Fold[t, Z, F]]
139129

140130
/** Converts a tuple `(T1, ..., Tn)` to `(F[T1], ..., F[Tn])` */
141-
type Map[Tup <: Tuple, F[_ <: Union[Tup]]] <: Tuple = Tup match {
131+
type Map[Tup <: Tuple, F[_ <: Union[Tup]]] <: Tuple = Tup match
142132
case EmptyTuple => EmptyTuple
143133
case h *: t => F[h] *: Map[t, F]
144-
}
145134

146135
/** Converts a tuple `(T1, ..., Tn)` to a flattened `(..F[T1], ..., ..F[Tn])` */
147-
type FlatMap[Tup <: Tuple, F[_ <: Union[Tup]] <: Tuple] <: Tuple = Tup match {
136+
type FlatMap[Tup <: Tuple, F[_ <: Union[Tup]] <: Tuple] <: Tuple = Tup match
148137
case EmptyTuple => EmptyTuple
149138
case h *: t => Concat[F[h], FlatMap[t, F]]
150-
}
151139

152140
/** Filters out those members of the tuple for which the predicate `P` returns `false`.
153141
* A predicate `P[X]` is a type that can be either `true` or `false`. For example:
@@ -160,31 +148,27 @@ object Tuple {
160148
* ```
161149
* @syntax markdown
162150
*/
163-
type Filter[Tup <: Tuple, P[_] <: Boolean] <: Tuple = Tup match {
151+
type Filter[Tup <: Tuple, P[_] <: Boolean] <: Tuple = Tup match
164152
case EmptyTuple => EmptyTuple
165-
case h *: t => P[h] match {
166-
case true => h *: Filter[t, P]
167-
case false => Filter[t, P]
168-
}
169-
}
153+
case h *: t => P[h] match
154+
case true => h *: Filter[t, P]
155+
case false => Filter[t, P]
170156

171157
/** Given two tuples, `A1 *: ... *: An * At` and `B1 *: ... *: Bn *: Bt`
172158
* where at least one of `At` or `Bt` is `EmptyTuple` or `Tuple`,
173159
* returns the tuple type `(A1, B1) *: ... *: (An, Bn) *: Ct`
174160
* where `Ct` is `EmptyTuple` if `At` or `Bt` is `EmptyTuple`, otherwise `Ct` is `Tuple`.
175161
*/
176-
type Zip[T1 <: Tuple, T2 <: Tuple] <: Tuple = (T1, T2) match {
162+
type Zip[T1 <: Tuple, T2 <: Tuple] <: Tuple = (T1, T2) match
177163
case (h1 *: t1, h2 *: t2) => (h1, h2) *: Zip[t1, t2]
178164
case (EmptyTuple, _) => EmptyTuple
179165
case (_, EmptyTuple) => EmptyTuple
180166
case _ => Tuple
181-
}
182167

183168
/** Converts a tuple `(F[T1], ..., F[Tn])` to `(T1, ... Tn)` */
184-
type InverseMap[X <: Tuple, F[_]] <: Tuple = X match {
169+
type InverseMap[X <: Tuple, F[_]] <: Tuple = X match
185170
case F[x] *: t => x *: InverseMap[t, F]
186171
case EmptyTuple => EmptyTuple
187-
}
188172

189173
/** Implicit evidence. IsMappedBy[F][X] is present in the implicit scope iff
190174
* X is a tuple for which each element's type is constructed via `F`. E.g.
@@ -194,22 +178,18 @@ object Tuple {
194178
type IsMappedBy[F[_]] = [X <: Tuple] =>> X =:= Map[InverseMap[X, F], F]
195179

196180
/** Transforms a tuple `(T1, ..., Tn)` into `(T1, ..., Ti)`. */
197-
type Take[T <: Tuple, N <: Int] <: Tuple = N match {
181+
type Take[T <: Tuple, N <: Int] <: Tuple = N match
198182
case 0 => EmptyTuple
199-
case S[n1] => T match {
200-
case EmptyTuple => EmptyTuple
201-
case x *: xs => x *: Take[xs, n1]
202-
}
203-
}
183+
case S[n1] => T match
184+
case EmptyTuple => EmptyTuple
185+
case x *: xs => x *: Take[xs, n1]
204186

205187
/** Transforms a tuple `(T1, ..., Tn)` into `(Ti+1, ..., Tn)`. */
206-
type Drop[T <: Tuple, N <: Int] <: Tuple = N match {
188+
type Drop[T <: Tuple, N <: Int] <: Tuple = N match
207189
case 0 => T
208-
case S[n1] => T match {
209-
case EmptyTuple => EmptyTuple
210-
case x *: xs => Drop[xs, n1]
211-
}
212-
}
190+
case S[n1] => T match
191+
case EmptyTuple => EmptyTuple
192+
case x *: xs => Drop[xs, n1]
213193

214194
/** Splits a tuple (T1, ..., Tn) into a pair of two tuples `(T1, ..., Ti)` and
215195
* `(Ti+1, ..., Tn)`.
@@ -231,23 +211,19 @@ object Tuple {
231211
def unapply(x: EmptyTuple): true = true
232212

233213
/** Convert an array into a tuple of unknown arity and types */
234-
def fromArray[T](xs: Array[T]): Tuple = {
235-
val xs2 = xs match {
214+
def fromArray[T](xs: Array[T]): Tuple =
215+
val xs2 = xs match
236216
case xs: Array[Object] => xs
237217
case xs => xs.map(_.asInstanceOf[Object])
238-
}
239218
runtime.Tuples.fromArray(xs2)
240-
}
241219

242220
/** Convert an immutable array into a tuple of unknown arity and types */
243-
def fromIArray[T](xs: IArray[T]): Tuple = {
244-
val xs2: IArray[Object] = xs match {
221+
def fromIArray[T](xs: IArray[T]): Tuple =
222+
val xs2: IArray[Object] = xs match
245223
case xs: IArray[Object] @unchecked => xs
246224
case _ =>
247225
xs.map(_.asInstanceOf[Object])
248-
}
249226
runtime.Tuples.fromIArray(xs2)
250-
}
251227

252228
/** Convert a Product into a tuple of unknown arity and types */
253229
def fromProduct(product: Product): Tuple =
@@ -260,18 +236,16 @@ object Tuple {
260236
given canEqualTuple[H1, T1 <: Tuple, H2, T2 <: Tuple](
261237
using eqHead: CanEqual[H1, H2], eqTail: CanEqual[T1, T2]
262238
): CanEqual[H1 *: T1, H2 *: T2] = CanEqual.derived
263-
}
264239

265240
/** A tuple of 0 elements */
266241
type EmptyTuple = EmptyTuple.type
267242

268243
/** A tuple of 0 elements. */
269-
case object EmptyTuple extends Tuple {
244+
case object EmptyTuple extends Tuple:
270245
override def toString(): String = "()"
271-
}
272246

273247
/** Tuple of arbitrary non-zero arity */
274-
sealed trait NonEmptyTuple extends Tuple {
248+
sealed trait NonEmptyTuple extends Tuple:
275249
import Tuple._
276250

277251
/** Get the i-th element of this tuple.
@@ -298,11 +272,9 @@ sealed trait NonEmptyTuple extends Tuple {
298272
inline def tail[This >: this.type <: NonEmptyTuple]: Tail[This] =
299273
runtime.Tuples.tail(this).asInstanceOf[Tail[This]]
300274

301-
}
302275

303276
@showAsInfix
304277
sealed abstract class *:[+H, +T <: Tuple] extends NonEmptyTuple
305278

306-
object *: {
279+
object `*:`:
307280
def unapply[H, T <: Tuple](x: H *: T): (H, T) = (x.head, x.tail)
308-
}

0 commit comments

Comments
 (0)