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
case class Person( | |
name: String, | |
age: Int) | |
case class Restaurant( | |
name: String, | |
brunch: Boolean) | |
// "ser" could just be "apply" |
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
46097 java.lang.Double | |
11799 java.lang.String | |
11458 _observervariable | |
11074 _set | |
7992 _letvariable | |
5257 _turtlevariable | |
5254 _call | |
4377 _patchvariable | |
4330 _breedvariable | |
3393 _ask |
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
// add zipWith to Iterable; thank you stackoverflow.com/q/3895813 | |
implicit class RichIterable[A, CC[X] <: Iterable[X]](xs: CC[A]) { | |
type Builder[C] = collection.generic.CanBuildFrom[Nothing, C, CC[C]] | |
def zipWith[B, C](ys: Iterable[B])(f: (A, B) => C)(implicit cbf: Builder[C]): CC[C] = | |
xs.zip(ys).map(f.tupled)(collection.breakOut) | |
} |
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-report pair [x l] | |
report map [list x ?] l | |
end | |
to-report pairs [l1 l2] | |
report reduce sentence map [pair ? l2] l1 | |
end |
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
public static class Reflect | |
extends DefaultCommand | |
implements org.nlogo.nvm.CustomAssembled | |
{ | |
public Syntax getSyntax() | |
{ | |
int[] right = { Syntax.TYPE_NUMBER , Syntax.TYPE_BOOLEAN_BLOCK , | |
Syntax.TYPE_COMMAND_BLOCK | Syntax.TYPE_OPTIONAL } ; | |
return Syntax.commandSyntax( right ) ; | |
} |
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
// BEFORE (Scala 2.9) | |
implicit def toRichLong(i: Long): MyRichLong = new MyRichLong(i) | |
class MyRichLong(i: Long) { | |
def digits: Seq[Int] = i.toString.map(_.asDigit) | |
} | |
// AFTER (Scala 2.10) | |
implicit class RichLong(i: Long) { |
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
trait Command | |
case class Forward(distance: Double) extends Command | |
case class Print(message: String) extends Command | |
case object Die extends Command | |
trait Agent | |
case object Observer extends Agent | |
case class Turtle(id: Long, var heading: Double = 0, var x: Double = 0, var y: Double = 0) extends Agent | |
case class Patch(px: Int, py: Int) extends Agent |
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
// The idea: instead of PlotListener with lots of methods, | |
// we have a PlotAction trait with lots of subclasses. | |
// what can we do with plot actions? | |
// - we can respond to them by mutating a plot on-screen | |
// but also: | |
// - we can write tests (are the right actions generated?) | |
// - we can record them for later replay (in e.g. recordable model runs) | |
// - we can broadcast them to a remote client |
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.File | |
import sbt._ | |
import Keys._ | |
object JFlexRunner { | |
val task = | |
(cacheDirectory, javaSource in Compile, streams) map { | |
(cacheDir, src, s) => | |
val cache = |
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> def lin: Stream[Int] = { println("foo"); 1 #:: { println("bar"); lin.map(_ + 1) } } | |
lin: Stream[Int] | |
scala> lin.take(5).force | |
foo | |
bar | |
foo | |
bar | |
foo | |
bar |