This file contains hidden or 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
| public class MyJavaClass { | |
| protected int bar = 1; | |
| } | |
| trait MyScalaTrait extends MyJavaClass { | |
| def foo = { | |
| bar = bar + 1 | |
| bar | |
| } |
This file contains hidden or 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
| trait T[A] | |
| trait Bar[A] { | |
| implicit def T: T[A] | |
| } | |
| trait Foo[A] extends Bar[A] | |
| class Cake[A: T](a: A) extends Foo[A] { | |
| def T: T[A] = implicitly |
This file contains hidden or 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 Ishi extends App { | |
| class Primes { | |
| val primes: Stream[Long] = 2 #:: primesStartingFrom(3) | |
| def isPrime(n: Long): Boolean = { | |
| val limit = math.sqrt(n).ceil.toInt | |
| !primes.takeWhile(_ < limit).exists(n % _ == 0) | |
| } |
This file contains hidden or 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
| lambda = Lpr + 6.288750 * sin(Mpr) | |
| + 1.274018 * sin(2*D - Mpr) | |
| + 0.658309 * sin(2*D) | |
| + 0.213616 * sin(2*Mpr) | |
| - e * 0.185596 * sin(M) | |
| - 0.114336 * sin(2*F) | |
| + 0.058793 * sin(2*D - 2*Mpr) | |
| + e * 0.057212 * sin(2*D - M - Mpr) | |
| + 0.053320 * sin(2*D + Mpr) | |
| + e * 0.045874 * sin(2*D - M) |
This file contains hidden or 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.annotation.tailrec | |
| object FirstDup extends App { | |
| def unfold[A, B](b: B)(f: B => Option[(A, B)]): Stream[A] = f(b) match { | |
| case None => Stream.empty | |
| case Some((a, b)) => a #:: unfold(b)(f) | |
| } | |
| def prefix[A](as: Traversable[A]): Stream[A] = |
This file contains hidden or 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
| package org.tpolecat.basic | |
| object Test extends App { | |
| val count = new BASIC { | |
| 10 FOR I IN 1 TO 2 | |
| 15 FOR J IN 1 TO 3 | |
| 20 GOSUB 100 | |
| 25 NEXT J |
This file contains hidden or 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
| trait Foo[A] | |
| implicit val c: Foo[Int] = ??? | |
| implicit val d: Foo[String] = ??? | |
| def bar[A: Foo]: A = ??? | |
| bar: Int // compiles only if Foo is covariant in A ... why? |
This file contains hidden or 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 WAT extends App { | |
| object Foo { | |
| def !:(n: => Any) = "foo" | |
| } | |
| lazy val a = { println("AAA"); 1 } | |
| lazy val b = { println("BBB"); 1 } | |
| Foo.`!:`(a) // ok |
This file contains hidden or 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
| class Curry { | |
| def foo(n:Int, s:String) = false | |
| def bar(n:Int)(s:String) = false | |
| } | |
| becomes | |
| cookie:crap rnorris$ javap -classpath bin Curry |
This file contains hidden or 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
| trait Ref[A] extends java.io.Externalizable | |
| trait Binary[A] | |
| def serializable[A <: java.io.Serializable]:Binary[A] = null | |
| implicit def ref[A]: Binary[Ref[A]] = serializable[Ref[A]] | |
| implicitly[Binary[Ref[Int]]] |