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 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 |
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
. 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 . . |
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> 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 |
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
//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) |
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
push = (element) -> (stack) -> | |
newStack = [element].concat stack | |
{value: element, stack: newStack} | |
pop = (stack) -> | |
element = stack[0] | |
newStack = stack.slice 1 | |
{value: element, stack: newStack} | |
bind = (stackOperation, continuation) -> (stack) -> |
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 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 ; |
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
#!/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 |
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
// 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. |
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
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)) | |
} |
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
alias cd="pushd $@ > /dev/null" |
OlderNewer