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
data Option a = Some a | None | |
let addOne o = match o | |
case (Some x) = x.value + 1 | |
case None = 1 | |
// addOne's type is: | |
// Option {value: Number} | |
// These compile: |
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
var e;function f(a,b){if(b>=0&&b<a.length)return b;h(aa(b))};Boolean.D=function(a){return typeof a=="boolean"||a instanceof Boolean};var i={},ba={};function ca(a,b){return function(c,d){return a.call(void 0,b,c,d)}}function j(a,b,c){return function(d,g,m){return a.call(b,c,d,g,m)}}function da(a,b,c){return function(d,g,m,p){return a.call(b,c,d,g,m,p)}}function ea(a,b){var c=fa;return function(d,g,m){return c.call(void 0,a,b,d,g,m)}}function ga(a,b){if(a.prototype.__proto__)a.prototype.__proto__=b.prototype;else{var c=function(){};c.prototype=b.prototype;a.prototype=new c;a.prototype.constructor=a}} | |
function k(a){if(!(typeof a=="function"?a():a))throw a=Error("Assertion failed. "),Error.captureStackTrace&&Error.captureStackTrace(a),a;}function ha(a,b){return typeof a=="number"&&typeof b=="number"?a+b:a.Pa(b)}function ia(a){a/=4;return a<0?Math.ceil(a):Math.floor(a)}function l(a,b){return a===void 0?b===void 0:typeof a=="number"&&typeof b=="number"?a==b:a.U(b)}function h(a){a&&typeof a=="object"&&Error.captureS |
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
module Happy where | |
import Control.Monad | |
import Control.Monad.State -- Brian | |
happy :: | |
Int | |
-> Bool | |
happy = | |
-- Start of Brian's code |
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
$ curl -Lvi google.com | |
* About to connect() to google.com port 80 (#0) | |
* Trying 74.125.224.206... connected | |
* Connected to google.com (74.125.224.206) port 80 (#0) | |
> GET / HTTP/1.1 | |
> User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5 | |
> Host: google.com | |
> Accept: */* | |
> | |
< HTTP/1.1 302 Moved Temporarily |
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
var stringMonoid = { | |
"append": function(x, y) { | |
return x + y; | |
}, | |
"empty": "" | |
}; | |
console.log(stringMonoid.append(stringMonoid.append("Hello!", stringMonoid.empty), stringMonoid.empty)); | |
var f = function(Monoid, x) { | |
return Monoid.append(Monoid.empty, x); | |
}; |
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
function some(a) { | |
return { | |
fold: function(f, _) { | |
return f(a); | |
}, | |
getOrElse: function(e) { | |
return a; | |
}, | |
orElse: function() { | |
return some(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 users [{:name "Brian" :age 22} {:name "Ben" :age 19}]) | |
;; Takes a "path", returns a function that takes an "object" and | |
;; returns a "costate" | |
(defn lens [p] | |
(fn [o] | |
{:get (get-in o p) | |
:set #(assoc-in o p %1)})) | |
(def myAgeLens (lens [0 :age])) |
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
function extend(o, e) { | |
var n = {}, i; | |
for(i in o) { | |
n[i] = o[i]; | |
} | |
for(i in e) { | |
n[i] = e[i]; | |
} | |
return 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 scalaz.WriterT | |
import scalaz.NonEmptyList | |
import scalaz.syntax.id._ | |
import scalaz.std.option._ | |
import scalaz.syntax.std.option._ | |
type OptionLogger[A] = WriterT[Option, NonEmptyList[String], A] | |
val two: OptionLogger[Int] = WriterT.put(2.some)("The number two".wrapNel) |
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
// This file shows a hack to achieve operator overloading in | |
// JavaScript. I have defined 3 different operators: | |
// | |
// >= = monadic bind | |
// >> = kleisli composition | |
// > = functor map | |
// * = applicative apply | |
// + = semigroup append | |
// | |
// Head straight to the bottom to see example usages. |