- Sequencing
Option
- Sequencing
Either
- Sequencing
Validated
- Sequencing
Future
ofOption
withOptionT
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
import scala.io.AnsiColor._ | |
def espace(couleur: String) = | |
couleur + " " + RESET | |
def image(w:Int, h: Int, f: (Int, Int) => String ) = | |
println((for (y <- -h to h) yield (for (x <- -w to w) yield espace(f(x,y))).mkString).mkString("\n")) | |
// 8 ellipses | |
image(70, 25, (x,y) => |
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
import math._ | |
import scala.scalajs.concurrent.JSExecutionContext.Implicits.queue | |
import ScalaFiddle.{Color, Epsilon} | |
import fiddle.Fiddle.{canvas, draw => renderer} | |
import scala.scalajs.js | |
import org.scalajs.dom | |
import scala.language.postfixOps | |
/** | |
* A simple ray tracer, taken from the PyPy benchmarks |
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
# Illustrates the compile-time dispatch that has to occur with macro overrides. | |
# You can install Ammonite-REPL (http://www.lihaoyi.com/Ammonite/#Ammonite-REPL), or use scala instead of amm | |
$ amm | |
Loading... | |
Welcome to the Ammonite Repl 0.9.3 | |
(Scala 2.12.2 Java 1.8.0_121) | |
@ import scala.reflect.macros.blackbox | |
import scala.reflect.macros.blackbox | |
@ import scala.language.experimental.macros | |
import scala.language.experimental.macros |
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
# Prerequisite: Install Ammonite-REPL (http://www.lihaoyi.com/Ammonite/#Ammonite-REPL) | |
$ amm | |
Loading... | |
Welcome to the Ammonite Repl 0.8.2 | |
(Scala 2.12.1 Java 1.8.0_66) | |
@ import $ivy.`org.typelevel::cats:0.9.0` | |
@ import scala.concurrent.Future | |
@ import scala.concurrent.ExecutionContext.Implicits.global | |
@ import cats.implicits._ | |
@ import cats.data.OptionT |
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
# Prerequisite: Install Ammonite-REPL (http://www.lihaoyi.com/Ammonite/#Ammonite-REPL) | |
$ amm | |
Loading... | |
Welcome to the Ammonite Repl 0.8.2 | |
(Scala 2.12.1 Java 1.8.0_66) | |
@ import $ivy.`org.typelevel::cats:0.9.0` | |
@ import cats.implicits._ | |
@ import cats.syntax.either._ | |
@ List(1.asRight, 2.asRight).sequenceU | |
res3: Either[Nothing, List[Int]] = Right(List(1, 2)) |
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
# Prerequisite: Install Ammonite-REPL (http://www.lihaoyi.com/Ammonite/#Ammonite-REPL) | |
$ amm | |
Loading... | |
Welcome to the Ammonite Repl 0.8.2 | |
(Scala 2.12.1 Java 1.8.0_66) | |
@ import $ivy.`org.typelevel::cats:0.9.0` | |
@ import cats.syntax.option._ | |
@ import cats.implicits._ | |
@ List(1.some, 2.some).sequenceU | |
res3: Option[List[Int]] = Some(List(1, 2)) |
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
# Prerequisite: Install Ammonite-REPL (http://www.lihaoyi.com/Ammonite/#Ammonite-REPL) | |
$ amm | |
Loading... | |
Welcome to the Ammonite Repl 0.8.2 | |
(Scala 2.12.1 Java 1.8.0_66) | |
@ import $ivy.`org.typelevel::cats:0.9.0` | |
@ import cats.implicits._ | |
@ import cats.data.Validated._ | |
@ List(2, 4).map(a => if (a % 2 == 0) valid(a) else invalidNel(a)).sequenceU | |
res5: cats.data.Validated[cats.data.NonEmptyList[Int], List[Int]] = Valid(List(2, 4)) |
I hereby claim:
- I am patrick-premont on github.
- I am ppremont (https://keybase.io/ppremont) on keybase.
- I have a public key whose fingerprint is 56CE CB40 3F90 A457 B270 F89C E79F 9E8E 931B D152
To claim this, I am signing this object:
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
scala> import pprint.Config.Colors._ | |
import pprint.Config.Colors._ | |
scala> case class Test(name: String, value: Int) | |
defined class Test | |
scala> pprint.pprintln(Test("a" * 10, 1)) | |
Test("aaaaaaaaaa", 1) | |
scala> pprint.pprintln(Test("a" * 10, 1))(implicitly, PPrintConfig.copy(showFieldNames = true)) |
NewerOlder