Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce Jar size by using instance constructors #1161

Merged
merged 2 commits into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import com.typesafe.sbt.SbtGit.GitKeys._
import sbtcrossproject.CrossPlugin.autoImport.crossProject
import sbtcrossproject.CrossProject

val Scala212 = "2.12.13"
Expand Down
12 changes: 12 additions & 0 deletions core/src/main/scala/shapeless/ops/functions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ object function {
}

object FnToProduct extends FnToProductInstances {
type Aux[F, P] = FnToProduct[F] { type Out = P }
def apply[F <: AnyRef](implicit fntop: FnToProduct[F]): Aux[F, fntop.Out] = fntop

private[shapeless] def instance[F, P](toProduct: F => P): Aux[F, P] = new FnToProduct[F] {
type Out = P
def apply(f: F) = toProduct(f)
}
}

/**
Expand All @@ -41,6 +47,12 @@ object function {
trait FnFromProduct[F] extends DepFn1[F] with Serializable

object FnFromProduct extends FnFromProductInstances {
type Aux[F, O] = FnFromProduct[F] { type Out = O }
def apply[F](implicit fnfromp: FnFromProduct[F]): Aux[F, fnfromp.Out] = fnfromp

private[shapeless] def instance[P, F](fromProduct: P => F): Aux[P, F] = new FnFromProduct[P] {
type Out = F
def apply(f: P) = fromProduct(f)
}
}
}
11 changes: 7 additions & 4 deletions core/src/main/scala/shapeless/ops/hlists.scala
Original file line number Diff line number Diff line change
Expand Up @@ -788,13 +788,16 @@ object hlist {
trait Tupler[L <: HList] extends DepFn1[L] with Serializable

object Tupler extends TuplerInstances {
type Aux[L <: HList, T] = Tupler[L] { type Out = T }
def apply[L <: HList](implicit tupler: Tupler[L]): Aux[L, tupler.Out] = tupler

private[shapeless] def instance[L <: HList, T](tuple: L => T): Aux[L, T] = new Tupler[L] {
type Out = T
def apply(l: L) = tuple(l)
}

implicit val hnilTupler: Aux[HNil, Unit] =
new Tupler[HNil] {
type Out = Unit
def apply(l: HNil): Out = ()
}
instance(_ => ())
}

/**
Expand Down
19 changes: 11 additions & 8 deletions core/src/main/scala/shapeless/sized.scala
Original file line number Diff line number Diff line change
Expand Up @@ -221,29 +221,32 @@ object AdditiveCollection {
import scala.collection.immutable.Queue
import scala.collection.LinearSeq

private[this] val instance =
new AdditiveCollection[Any] {}

implicit def linearSeqAdditiveCollection[T]: AdditiveCollection[LinearSeq[T]] =
new AdditiveCollection[LinearSeq[T]] {}
instance.asInstanceOf[AdditiveCollection[LinearSeq[T]]]

implicit def vectorAdditiveCollection[T]: AdditiveCollection[Vector[T]] =
new AdditiveCollection[Vector[T]] {}
instance.asInstanceOf[AdditiveCollection[Vector[T]]]

implicit def arrayAdditiveCollection[T]: AdditiveCollection[Array[T]] =
new AdditiveCollection[Array[T]] {}
instance.asInstanceOf[AdditiveCollection[Array[T]]]

implicit def stringAdditiveCollection: AdditiveCollection[String] =
new AdditiveCollection[String] {}
instance.asInstanceOf[AdditiveCollection[String]]

implicit def listAdditiveCollection[T]: AdditiveCollection[List[T]] =
new AdditiveCollection[List[T]] {}
instance.asInstanceOf[AdditiveCollection[List[T]]]

implicit def streamAdditiveCollection[T]: AdditiveCollection[LazyList[T]] =
new AdditiveCollection[LazyList[T]] {}
instance.asInstanceOf[AdditiveCollection[LazyList[T]]]

implicit def queueAdditiveCollection[T]: AdditiveCollection[Queue[T]] =
new AdditiveCollection[Queue[T]] {}
instance.asInstanceOf[AdditiveCollection[Queue[T]]]

implicit def defaultAdditiveCollection[T]: AdditiveCollection[collection.immutable.IndexedSeq[T]] =
new AdditiveCollection[collection.immutable.IndexedSeq[T]] {}
instance.asInstanceOf[AdditiveCollection[collection.immutable.IndexedSeq[T]]]
}

class DefaultToIndexedSeq[CC[_]]
Expand Down
Loading