diff --git a/core/shared/src/main/scala/scalacss/internal/Css.scala b/core/shared/src/main/scala/scalacss/internal/Css.scala index 27f7536a..2061451d 100644 --- a/core/shared/src/main/scala/scalacss/internal/Css.scala +++ b/core/shared/src/main/scala/scalacss/internal/Css.scala @@ -2,17 +2,25 @@ package scalacss.internal object Css { - def apply(ss: TraversableOnce[StyleA], kfs: TraversableOnce[Keyframes], ff: TraversableOnce[FontFace[String]])(implicit env: Env): Css = - styles(ss) append keyframes(kfs) append fontFaces(ff) + def apply(ss: TraversableOnce[StyleA], + kfs: TraversableOnce[Keyframes], + ff: TraversableOnce[FontFace[String]]) + (implicit env: Env): Css = { + val b = Vector.newBuilder[CssEntry] + b ++= styles(ss) + b ++= keyframes(kfs) + b ++= fontFaces(ff) + b.result() + } def styles(ss: TraversableOnce[StyleA])(implicit env: Env): StyleStream = - ss.toStream flatMap styleA + ss.toIterator.flatMap(styleA).toVector def keyframes(kfs: TraversableOnce[Keyframes])(implicit env: Env): KeyframeStream = - kfs.toStream map keyframes + kfs.toIterator.map(keyframes).toList def fontFaces(ff: TraversableOnce[FontFace[String]]): FontFaceStream = - ff.toStream map fontFaces + ff.toIterator.map(fontFaces).toList def className(cn: ClassName): CssSelector = "." + cn.value @@ -36,21 +44,21 @@ object Css { style(className(s.className), s.style) def style(sel: CssSelector, s: StyleS)(implicit env: Env): StyleStream = { - def main: StyleStream = - s.data.toStream.flatMap { + def main: Iterator[CssEntry.Style] = + s.data.iterator.flatMap { case (cond, avs) => val kvs = avs.avIterator.map(_(env)).foldLeft(Vector.empty[CssKV])(_ ++ _) - NonEmptyVector.maybe(kvs, Stream.empty[CssEntry.Style]) {c => + NonEmptyVector.maybe(kvs, List.empty[CssEntry.Style]) { c => val mq = mediaQuery(cond) - val s = selector(sel, cond) - Stream(CssEntry.Style(mq, s, c)) + val s = selector(sel, cond) + CssEntry.Style(mq, s, c) :: Nil } } - def exts: StyleStream = - s.unsafeExts.toStream.flatMap(unsafeExt(sel, _)) + def exts: Iterator[CssEntry.Style] = + s.unsafeExts.toIterator.flatMap(unsafeExt(sel, _)) - main append exts + (main ++ exts).toVector } def unsafeExt(root: CssSelector, u: Style.UnsafeExt)(implicit env: Env): StyleStream = { @@ -62,9 +70,9 @@ object Css { type ByMediaQuery = Map[CssMediaQueryO, ValuesByMediaQuery] def separateStylesAndKeyframes(c: Css): (StyleStream, KeyframeStream, FontFaceStream) = { - val styles = Stream.newBuilder[CssEntry.Style] - val animations = Stream.newBuilder[CssEntry.Keyframes] - val fontFaces = Stream.newBuilder[CssEntry.FontFace] + val styles = Vector.newBuilder[CssEntry.Style] + val animations = List.newBuilder[CssEntry.Keyframes] + val fontFaces = List.newBuilder[CssEntry.FontFace] c.foreach { case e: CssEntry.Style => styles += e case e: CssEntry.Keyframes => animations += e @@ -82,14 +90,14 @@ object Css { } } - def flatten(css: StyleStream): Stream[(CssMediaQueryO, CssSelector, CssKV)] = + def flatten(css: StyleStream): Vector[(CssMediaQueryO, CssSelector, CssKV)] = css.flatMap { case CssEntry.Style(mq, sel, kvs) => - kvs.toStream.map(kv => (mq, sel, kv)) + kvs.iterator.map(kv => (mq, sel, kv)) } type Flat4 = (CssMediaQueryO, CssSelector, String, String) - def flatten4(css: StyleStream): Stream[Flat4] = + def flatten4(css: StyleStream): Vector[Flat4] = css.flatMap { case CssEntry.Style(mq, sel, kvs) => - kvs.toStream.map(kv => (mq, sel, kv.key, kv.value)) + kvs.iterator.map(kv => (mq, sel, kv.key, kv.value)) } } \ No newline at end of file diff --git a/core/shared/src/main/scala/scalacss/internal/NonEmptyVector.scala b/core/shared/src/main/scala/scalacss/internal/NonEmptyVector.scala index 8f453326..e305d2bd 100644 --- a/core/shared/src/main/scala/scalacss/internal/NonEmptyVector.scala +++ b/core/shared/src/main/scala/scalacss/internal/NonEmptyVector.scala @@ -61,7 +61,6 @@ final class NonEmptyVector[+A](val head: A, val tail: Vector[A]) { foldMapLeft1(f)((b, a) => g(b, f(a))) def toSet[B >: A] = whole.toSet[B] - def toStream = whole.toStream } // ===================================================================================================================== diff --git a/core/shared/src/main/scala/scalacss/internal/package.scala b/core/shared/src/main/scala/scalacss/internal/package.scala index ef20373d..25cbf242 100644 --- a/core/shared/src/main/scala/scalacss/internal/package.scala +++ b/core/shared/src/main/scala/scalacss/internal/package.scala @@ -34,15 +34,15 @@ package object internal { type KeyframeAnimationName = ClassName type KeyframeSelector = Percentage[_] - type StyleStream = Stream[CssEntry.Style] - type KeyframeStream = Stream[CssEntry.Keyframes] - type FontFaceStream = Stream[CssEntry.FontFace] + type StyleStream = Vector[CssEntry.Style] + type KeyframeStream = List[CssEntry.Keyframes] + type FontFaceStream = List[CssEntry.FontFace] /** * A stylesheet in its entirety. Normally turned into a `.css` file or a `<style>` tag. */ - type Css = Stream[CssEntry] - implicit def univEqCss: UnivEq[Css] = UnivEq.univEqStream + type Css = Vector[CssEntry] + implicit def univEqCss: UnivEq[Css] = UnivEq.univEqVector type WarningMsg = String final case class Warning(cond: Cond, msg: WarningMsg) diff --git a/doc/history/0.5.md b/doc/history/0.5.md index 23276069..1e9b844a 100644 --- a/doc/history/0.5.md +++ b/doc/history/0.5.md @@ -69,3 +69,5 @@ * scalajs-react 1.0.0. * Compile for Scala 2.12 with `-opt:l:method` + +* Replace all instance of `Stream` with `List`, `Vector` or `Iterator`