(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
#!/usr/bin/python3.5 | |
# Author: Dagang Wei (github.com/weidagang) | |
# Created: 2016-11-19 | |
# Last modified: 2016-11-27 | |
# License: MIT | |
# Self link: https://gist.github.com/weidagang/1b001d0e55c4eff15ad34cc469fafb84 | |
# | |
# This code demonstrates the core algorithm for distributed MVCC based cross-row | |
# transactions. The algorithm is built on top of a distributed key-value database |
const daggy = require('daggy') | |
const compose = (f, g) => x => f(g(x)) | |
const id = x => x | |
//===============Define Coyoneda========= | |
const Coyoneda = daggy.tagged('x', 'f') | |
Coyoneda.prototype.map = function(f) { | |
return Coyoneda(this.x, compose(f, this.f)) | |
} |
. 5 . | . . 1 | 4 7 9 | |
. . 2 | 7 . . | . . 8 | |
. . . | . 4 6 | 2 . . | |
------+-------+------ | |
. 4 6 | . . 9 | 5 3 7 | |
. . . | . 6 . | . . . | |
8 9 3 | 5 . . | 6 4 . | |
------+-------+------ | |
. . 9 | 6 1 . | . . . | |
1 . . | . . 2 | 3 . . |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
import Control.Monad (guard) | |
-- either one is true | |
xor :: Bool -> Bool -> Bool | |
xor = (/=) | |
distinct :: Eq a => [a] -> Bool | |
distinct [] = True | |
distinct (x:xs) = x `notElem` xs && distinct xs |
package java8tests ; | |
import java.util.function.BiFunction ; | |
import java.util.function.Function ; | |
public class Currying { | |
public void currying() { | |
// Create a function that adds 2 integers | |
BiFunction<Integer,Integer,Integer> adder = ( a, b ) -> a + b ; |
// Utility function for detecting generators. | |
let isGenerator = x => { | |
return Function.isGenerator && | |
Function.isGenerator.call(x) | |
} | |
// Data type represents channel into which values | |
// can be `put`, or `received` from. Channel is | |
// very much like queue where reads and writes are | |
// synchronized via continuation passing. |
//BASIC PIECES, 3 functions: unit, bind and the bind argument | |
//function unit(value) | |
//function bind(monad, function(value)) | |
//all three functions return a monad | |
/* The unit function is a constructor (returns a monad object) | |
* The magic is in the bind function | |
* | |
* There are AXIOMS: | |
* bind(unit(value)), f) === f(value) |
/* | |
* Example of a state monad in use. This is adapted from an example on | |
* the Haskell Wiki: | |
* http://www.haskell.org/haskellwiki/State_Monad#Complete_and_Concrete_Example_1 | |
*/ | |
require(['state', 'qunit'], function(state, qunit) { | |
/* | |
* playGame() is a recursive function that given an array of moves | |
* defines an algorithm for constructing a final game score. Along |
scala> import scalaz._ | |
import scalaz._ | |
scala> import Scalaz._ | |
import Scalaz._ | |
scala> val a = (value: Int) => value * 2 | |
a: Int => Int = <function1> | |
scala> val b = (value: Int) => value + 1 |