Scalaz | |||
Symbol | Code | Ascii | Example |
---|---|---|---|
η | 951 | pure | 1.η[List] |
μ | 03BC | join | List(List(1,2,3), nil, List(5,6,7)) μ |
∅ | 2205 | zero | ∅[Int] |
<∅> | empty | <∅>[Option, Int] |
|
∙ | 2219 | contramap | ((_:String).length ∙ (_:Int).toString ∙ ((_:Int) + 6))(5) |
∘ | 2218 | map | (((_:Int) + 6) ∘ (_:Int).toString ∘ (_:String).length)(5) |
∘∘ |
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
### Keybase proof | |
I hereby claim: | |
* I am folone on github. | |
* I am folone (https://keybase.io/folone) on keybase. | |
* I have a public key whose fingerprint is 5B9B 8355 136D CA8B F2DD F8CE EC51 AF2A 9ABC 8D1B | |
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
### Keybase proof | |
I hereby claim: | |
* I am folone on github. | |
* I am folone (https://keybase.io/folone) on keybase. | |
* I have a public key whose fingerprint is 3A57 D1D4 67F6 0189 3CB7 03D8 FA5C 9955 37B3 71EF | |
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> trait Assoc[K] { type V ; val value: V } | |
defined trait Assoc | |
scala> def mkAssoc[K, V0](k: K, v: V0): Assoc[k.type] { type V = V0 } = | |
| new Assoc[k.type] { type V = V0 ; val value = v } | |
mkAssoc: [K, V0](k: K, v: V0)Assoc[k.type]{type V = V0} | |
scala> def lookup[K](k: K)(implicit assoc: Assoc[k.type]): assoc.V = assoc.value | |
lookup: [K](k: K)(implicit assoc: Assoc[k.type])assoc.V |
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
> ++2.10.4 | |
[info] Setting version to 2.10.4 | |
[info] Set current project to wartremover (in build file:/Users/georgii/workspace/wartremover/) | |
> console | |
[info] Updating {file:/Users/georgii/workspace/wartremover/}wartremover... | |
[info] Resolving org.fusesource.jansi#jansi;1.4 ... | |
[info] Done updating. | |
[info] Compiling 24 Scala sources to /Users/georgii/workspace/wartremover/target/scala-2.10/classes... | |
[info] Starting scala interpreter... | |
[info] |
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 play.api.libs.json._ | |
import play.api.libs.json._ | |
scala> case class Test[A: Writes](a: A) | |
defined class Test | |
scala> implicit def testWrites[A: Writes] = Json.writes[Test[A]] | |
<console>:12: error: No apply function found matching unapply parameters | |
implicit def testWrites[A: Writes] = Json.writes[Test[A]] | |
^ |
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
def ackermann(m: Int, n: Int): Int = { | |
(m, n) match { | |
case (0, _) ⇒ n + 1 | |
case (m, 0) if m > 0 ⇒ ackermann(m - 1, 1) | |
case (m, n) if m > 0 && n > 0 ⇒ ackermann(m - 1, ackermann(m, n - 1)) | |
} | |
} | |
import scalaz._, Scalaz._, Free.{suspend ⇒ _, _}, Trampoline._ | |
def ackermannTramp(m: Int, n: Int): Trampoline[Int] = { |
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
> shapeless-examples/console | |
[warn] Credentials file /home/folone/.ivy2/.credentials does not exist | |
[warn] Binary version (2.10) for dependency org.scala-lang#scala-library;2.10.2 | |
[warn] in com.chuusai#shapeless_2.10.2;2.0.0-SNAPSHOT differs from Scala binary version in project (2.10.2). | |
[warn] Binary version (2.10) for dependency org.scala-lang#scala-compiler;2.10.2 | |
[warn] in com.chuusai#shapeless_2.10.2;2.0.0-SNAPSHOT differs from Scala binary version in project (2.10.2). | |
[info] Starting scala interpreter... | |
[info] | |
Welcome to Scala version 2.10.2 (OpenJDK 64-Bit Server VM, Java 1.7.0_40). | |
Type in expressions to have them evaluated. |
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
final val BATCH_SIZE = (Runtime.getRuntime.freeMemory / 1024).toInt // kb per object should be enough, right? | |
def doStuff(m: MyType): Stream[MyType] = ??? // Costly operation | |
val s: Stream[MyType] = ??? | |
s.grouped(BATCH_SIZE).toStream.flatMap(_.par flatMap doStuff) |
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
/* | |
* http://dysphoria.net/code/hindley-milner/HindleyMilner.scala | |
* Andrew Forrest | |
* | |
* Implementation of basic polymorphic type-checking for a simple language. | |
* Based heavily on Nikita Borisov’s Perl implementation at | |
* http://web.archive.org/web/20050420002559/www.cs.berkeley.edu/~nikitab/courses/cs263/hm.html | |
* which in turn is based on the paper by Luca Cardelli at | |
* http://lucacardelli.name/Papers/BasicTypechecking.pdf | |
* |
NewerOlder