Skip to content

Instantly share code, notes, and snippets.

@mpilquist
mpilquist / announcement.md
Created February 13, 2017 16:15
FS2 0.9.3

FS2 0.9.3 Release Announcement

FS2 0.9.3 is now available!

This release is focused on performance and includes an important bugfix for a memory leak in Signal#discrete. The full changelog is available here.

0.9.3 is backwards compatible with earlier releases in the 0.9 series.

There are a number of contributors to this release, including many new contributors:

import java.time.Instant
import scala.concurrent.duration._
import fs2._
object Retries {
/**
* Returns a stream that evaluates the specified task once and then for each unit that appears in the `changes` stream. If any task evaluation
* fails with an exception, the task is retried according to the specified `retryDelay` schedule until it succeeds or a value from the `changes`
* stream appears.
scala> case class Foo(x: Int, y: Boolean)
defined class Foo
scala> def foo(a: Foo) = a match { case Foo(x, y) => x }
foo: (a: Foo)Int
scala> :javap foo
Size 902 bytes
MD5 checksum 407f62b7f6559375f60f39b82fc98b9b
Compiled from "<console>"
@mpilquist
mpilquist / lastb.scala
Last active June 2, 2021 21:25
FS2 example of merging two streams and outputting the last received B value with each A value
@ def lastB[F[_]: Async, A, B]: Pipe2[F, A, B, (A, B)] = {
def go(
lastB: B,
l: ScopedFuture[F, Pull[F, Nothing, (Option[A], Handle[F,A])]],
r: ScopedFuture[F, Pull[F, Nothing, (Option[B], Handle[F,B])]]
): Pull[F,(A, B),Nothing] =
(l race r).pull flatMap {
case Left(l) => l.optional flatMap {
case None => Pull.done
case Some((None, l)) => Pull.done
package scratch
sealed trait Sub1[-F[_],+G[_]] {
def apply[A](f: F[A]): G[A]
}
object Sub1 {
implicit def sub1[F[_]]: Sub1[F,F] = new Sub1[F,F] { def apply[A](f: F[A]) = f }
}
› amm
Loading...
Welcome to the Ammonite Repl 0.7.6
(Scala 2.11.8 Java 1.8.0_65)
@ import $ivy.`org.scalaz.stream::scalaz-stream:0.7.3a`
:: loading settings :: url = jar:file:/usr/local/Cellar/ammonite-repl/0.7.6/bin/amm!/org/apache/ivy/core/settings/ivysettings.xml
:: resolving dependencies :: org.scalaz.stream#scalaz-stream_2.11-caller;working
confs: [default]
found org.scalaz.stream#scalaz-stream_2.11;0.7.3a in chain-resolver
[0.7.3a] org.scalaz.stream#scalaz-stream_2.11;0.7.3a
› amm
Loading...
Welcome to the Ammonite Repl 0.7.6
(Scala 2.11.8 Java 1.8.0_65)
@ import $ivy.`org.scalaz::scalaz-core:7.2.6`
:: loading settings :: url = jar:file:/usr/local/Cellar/ammonite-repl/0.7.6/bin/amm!/org/apache/ivy/core/settings/ivysettings.xml
:: resolving dependencies :: org.scalaz#scalaz-core_2.11-caller;working
confs: [default]
found org.scalaz#scalaz-core_2.11;7.2.6 in chain-resolver
found org.scala-lang#scala-library;2.11.8 in chain-resolver
@mpilquist
mpilquist / changes.diff
Created July 5, 2016 14:48
scalaz-stream 0.8 failure under 2.12.0-M5
diff --git a/build.sbt b/build.sbt
index bb7ea68..7497062 100644
--- a/build.sbt
+++ b/build.sbt
@@ -23,7 +23,7 @@ git.formattedShaVersion := {
scalaVersion := "2.11.8"
-crossScalaVersions := Seq("2.10.6", "2.11.8", "2.12.0-M4")
+crossScalaVersions := Seq("2.10.6", "2.11.8", "2.12.0-M5")
@mpilquist
mpilquist / A.scala
Created March 12, 2016 00:15
Regression in 2.11.8
class A {
private case class B(x: Int)
private object B {
val z = B(0)
}
val a = B.z.x
}
/* Compiling under 2.11.7 and running (new A).a results in 0
Compiling under 2.11.8 and running (new A).a results in SOE:
@mpilquist
mpilquist / document.scala
Created March 3, 2016 18:48
Example of using scodec to decode a document of fields
package foo
import scodec.bits._
import scodec._
import scodec.codecs._
case class Document(fields: Vector[(String, Field)])
sealed trait Field
case class IntField(value: Int) extends Field