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
val e = Option(List(Right(2), Left("bad"))) | |
runResult { | |
for { | |
as <- (e must beSome).opt | |
a <- fromList(as) | |
i <- (a must beRight).opt | |
_ <- (i must be_>(0)).check | |
} yield () | |
} |
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
To realize the benefits of vertical alignment: | |
- code must be *self-formatting* | |
- deltas must be *semantic* | |
Each is within reach today, with moderate effort: | |
- edit *virtual* files which continuously adapt | |
- store semantic actions in a parallel VCS |
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.language.higherKinds | |
/* | |
* The usual peano numbers with addtion and multiplication | |
*/ | |
sealed trait Nat { | |
type Plus[N <: Nat] <: Nat | |
type Mult[N <: Nat] <: Nat | |
} |
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
:paste | |
type ErrorMessage = String | |
trait LeftBiased | |
trait RightBiased | |
sealed abstract class Or[+G, +B] extends LeftBiased { | |
def map[H](f: G => H): H Or B |
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 cats._, data._ | |
object Test { | |
trait Decoder[T] { | |
def decode(s: String): String Xor T | |
} | |
case class Password(pw: String) | |
case class User(name: String) |
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> trait Label[T] { val value: Boolean } | |
defined trait Label | |
scala> def mkInstance(s: String, v: Boolean): Label[s.type] = new Label[s.type] { val value = v } | |
mkInstance: (s: String, v: Boolean)Label[s.type] | |
scala> implicit def lTrue = mkInstance("True", true) | |
lTrue: Label[String("True")] | |
scala> implicit def lFalse = mkInstance("False", false) |
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
data:text/html, <html contenteditable style="font-family:Courier New, Sans Serif;font-size:90px"> |
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> class Foo { self: Singleton => } | |
defined class Foo | |
scala> class Bar extends Foo | |
<console>:12: error: illegal inheritance; | |
self-type Bar does not conform to Foo's selftype Foo with Singleton | |
class Bar extends Foo | |
^ | |
scala> object Bar extends Foo |
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
object Main { | |
val s1 = Set[BigDecimal](-4.872401723124452E9, 0, 1.1752011936438014, 8.696374707602505E17, -1.1752011936438014) | |
val s2 = Set[Double] (-4.872401723124452E9, 0, 1.1752011936438014, 8.696374707602505E17, -1.1752011936438014) | |
val s3: Set[BigDecimal] = s2 map (d => BigDecimal(d)) | |
def main(args: Array[String]): Unit = { | |
/* false */ println(s1 == s2) | |
/* true */ println(s1 == s3) | |
/* false */ println(s2 == s3) | |
/* true */ println(s1.toSeq.sorted == s2.toSeq.sorted) |
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 shapeless._ | |
/** | |
* Functional update of common fields of an *open* family of case classes | |
* via a case-class-like copy through the common super type ... | |
* | |
* This is a follow up to my earlier post showin how to do functional | |
* update for a sealed family of case classes, | |
* | |
* https://gist.github.com/milessabin/a212d946aef33811fee1 |