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
-- mouse highlighting | |
_c = require("hs.canvas") | |
function createCanvas(screen) | |
local cp = hs.mouse.getAbsolutePosition() | |
local f = screen:frame() | |
canvas = _c.new(f):show() | |
canvas[1] = { | |
action = "build", | |
type = "circle", |
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
implicit class ArgmaxColl[A, CC[X] <: Seq[X]](val coll: CC[A]) extends AnyVal { | |
def argmax(implicit o:Ordering[A]): Int = coll.indices.maxBy(coll) | |
} | |
val as = scala.util.Random.shuffle(1 to 10) | |
as.argmax |
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 plus012 = Array((_: Int) + 0, | |
(_: Int) + 1, | |
(_: Int) + 2) | |
/* plus012.apply(1) で (_: Int) + 1 を取り出して、2 を渡す */ | |
plus012(1)(2) // 3 | |
/* SeqがPartialFunction[Int, A]を継承しているので orElseを呼べる | |
* plus: PartialFunction[Int, (Int) => Int] */ | |
val plus = plus012.orElse[Int, Int => Int] { case i => (_: Int) + i } |
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 n = reset { | |
println("A") | |
val num = shift { (cont: Int => Int) => | |
println("B") | |
cont(cont(1)) | |
} | |
println("num", num) | |
num * 2 | |
} | |
println("n", n) |
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 java.io.PrintWriter | |
import scala.io.Source | |
import scala.util.continuations._ | |
trait ContextType[B] | |
def contextType[B]: ContextType[B] = null | |
def using[A <: AutoCloseable, B: ContextType](resource: A)(op: A => 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 java.io.PrintWriter | |
import scala.io.Source | |
implicit class Using[T <: AutoCloseable](resource: T) { | |
def foreach[R](op: T => R): R = { | |
try op(resource) | |
catch { case e: Exception => throw e } | |
finally resource.close() | |
} |
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
package yuima.funcpearls | |
import scala.annotation.tailrec | |
/** Scala implementation of "Solving the Snake Cube Puzzle in Haskel." | |
* http://web.cecs.pdx.edu/~mpj/snakecube/revised-SnakeCube.pdf | |
* | |
* Note: No implementation for a function "advance" in section 9. | |
* | |
* @author Yuichiroh Matsubayashi |
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> object Label extends Enumeration{ | |
| val ga, o, ni, none = Value | |
| } | |
defined object Label | |
scala> Label.values | |
res0: Label.ValueSet = Label.ValueSet(ga, o, ni, none) | |
scala> Label.values.map(_.toString) | |
res1: scala.collection.immutable.SortedSet[String] = TreeSet(ga, ni, none, o) |
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 foo(func: Boolean => Int) = ??? | |
def foo(func: Int => 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
object OverloadSample { | |
implicit class B2I(f: Boolean => Int) | |
implicit class I2I(f: Int => Int) | |
def foo(func: B2I): Unit = { | |
println("test") | |
} |
NewerOlder