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
# Implementation defines behaviour instead of state. | |
None = | |
map: (func) -> None | |
flatMap: (func) -> None | |
forEach: (func) -> # Nothing! | |
getOrElse: (def) -> def | |
isDefined: () -> false | |
fold: (empty, notEmpty) -> empty() | |
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 java.sql.{Connection, DriverManager} | |
import scala.util.Try | |
import java.net.{URISyntaxException, URI} | |
/** Object abstracts away some of the connection sheneanigans you need to do | |
* if you're trying to use JDBC. This is nice if you're just trying to make | |
* something of very simple with anorm (i.e., without Play! framework). | |
*/ | |
object SqlConnection { | |
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 Effect | |
constructor: (@object, @sideEffect) -> | |
map: (func) -> | |
copy = clone(@object) | |
@sideEffect(copy) | |
new Effect(copy, func) | |
flatMap: (func) -> |
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 sbt._ | |
import Keys._ | |
import java.io.File | |
object FunBuild extends Build { | |
lazy val root = Project(id = "root", base = file(".")).settings( | |
name := "Fun", | |
version := "0.1", |
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 Message | |
class Greeting extends Message | |
class Shout extends Message | |
class Farewell extends Message | |
# Curry for reusing the match | |
match = (patterns...) -> (val) -> | |
for pat in patterns | |
if val instanceof pat[0] then return pat[1](val) |
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 java.io.File | |
import akka.actor._ | |
import scala.concurrent.{ExecutionContext, Promise, Future} | |
import scala.util.{Success, Failure} | |
/** All IO methods */ | |
object FileIO { |
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
var privateApi = { | |
privateFunction: function() { | |
console.log('this method cannot be invoked by the injected code.'); | |
} | |
}; | |
var api = { | |
log: function() { | |
console.log('Sandbox says'); | |
Array.prototype.forEach.call(arguments, function(arg){ console.log(arg) }); |
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
var canvas = document.getElementsByTagName('canvas')[0] | |
canvas.width = window.innerWidth | |
canvas.height = window.innerHeight | |
var gl = canvas.getContext('webgl') | |
gl.clearColor(1, 0, 1, 1) | |
gl.clear(gl.COLOR_BUFFER_BIT) | |
var vertexShader = gl.createShader(gl.VERTEX_SHADER) |
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
// immutable linked list | |
// Some functional patterns use head/tail a *lot*, and this particular collection | |
// has constant time for both head and tail. Concatenation is also constant time. | |
var nil = {}; | |
// used to make the fields on the list truly immutable | |
function props(obj, fields){ | |
var args = {}; | |
for(var key in fields){ |
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
> var pipe = require('./pipe') | |
undefined | |
> var spread = pipe.spread | |
undefined | |
> function upper(s) { return s.toUpperCase() } | |
undefined | |
> pipe('foo',upper) | |
'FOO' | |
> function splitter(sp) { return function(str) { return str.split(sp) } } | |
undefined |
OlderNewer