-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use
Repeated
arguments instead of inline varargs
- Loading branch information
Showing
10 changed files
with
232 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.virtuslab.iskra | ||
|
||
import scala.compiletime.error | ||
|
||
// TODO should it be covariant or not? | ||
trait CollectColumns[-C]: | ||
type CollectedColumns <: Tuple | ||
def underlyingColumns(c: C): Seq[UntypedColumn] | ||
|
||
// Using `given ... with { ... }` syntax might sometimes break pattern match on `CollectColumns[...] { type CollectedColumns = cc }` | ||
|
||
object CollectColumns extends CollectColumnsLowPrio: | ||
given collectSingle[S <: Tuple]: CollectColumns[NamedColumns[S]] with | ||
type CollectedColumns = S | ||
def underlyingColumns(c: NamedColumns[S]) = c.underlyingColumns | ||
|
||
given collectEmptyTuple[S]: CollectColumns[EmptyTuple] with | ||
type CollectedColumns = EmptyTuple | ||
def underlyingColumns(c: EmptyTuple) = Seq.empty | ||
|
||
given collectMultiCons[S <: Tuple, T <: Tuple](using collectTail: CollectColumns[T]): (CollectColumns[NamedColumns[S] *: T] { type CollectedColumns = Tuple.Concat[S, collectTail.CollectedColumns] }) = | ||
new CollectColumns[NamedColumns[S] *: T]: | ||
type CollectedColumns = Tuple.Concat[S, collectTail.CollectedColumns] | ||
def underlyingColumns(c: NamedColumns[S] *: T) = c.head.underlyingColumns ++ collectTail.underlyingColumns(c.tail) | ||
|
||
// TODO Customize error message for different operations with an explanation | ||
class CannotCollectColumns(typeName: String) | ||
extends Exception(s"Could not find an instance of CollectColumns for ${typeName}") | ||
|
||
|
||
trait CollectColumnsLowPrio: | ||
given collectSingleCons[S, T <: Tuple](using collectTail: CollectColumns[T]): (CollectColumns[NamedColumns[S] *: T] { type CollectedColumns = S *: collectTail.CollectedColumns}) = | ||
new CollectColumns[NamedColumns[S] *: T]: | ||
type CollectedColumns = S *: collectTail.CollectedColumns | ||
def underlyingColumns(c: NamedColumns[S] *: T) = c.head.underlyingColumns ++ collectTail.underlyingColumns(c.tail) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.virtuslab.iskra | ||
|
||
type Repeated[A] = | ||
A | ||
| (A, A) | ||
| (A, A, A) | ||
| (A, A, A, A) | ||
| (A, A, A, A, A) | ||
| (A, A, A, A, A, A) | ||
| (A, A, A, A, A, A, A) | ||
| (A, A, A, A, A, A, A, A) | ||
| (A, A, A, A, A, A, A, A, A) | ||
| (A, A, A, A, A, A, A, A, A, A) | ||
| (A, A, A, A, A, A, A, A, A, A, A) | ||
| (A, A, A, A, A, A, A, A, A, A, A, A) | ||
| (A, A, A, A, A, A, A, A, A, A, A, A, A) | ||
| (A, A, A, A, A, A, A, A, A, A, A, A, A, A) | ||
| (A, A, A, A, A, A, A, A, A, A, A, A, A, A, A) | ||
| (A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A) | ||
| (A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A) | ||
| (A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A) | ||
| (A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A) | ||
| (A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A) | ||
| (A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A) | ||
| (A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A) // 22 is maximal arity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.