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
typealias PlusMinusable = protocol<IntegerArithmeticType, ForwardIndexType> | |
infix operator ± {} | |
struct PlusMinus<T: PlusMinusable> { | |
let value: T | |
let variance: T | |
var range: Range<T> { | |
let lower = value - variance | |
let upper = value + variance |
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
let unwrapMe: [[Int]] = [] | |
// IF LET | |
func unwrapWithIfLet (arrArr: [[Int]]) -> Int? { | |
if let x = arrArr.first?.first { | |
return x + 1 | |
} | |
return nil | |
} |
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
//-- | |
//-- FUNCTORS in ES6 | |
//-- | |
//-- BOILER PLATE | |
let fmap = (f) => (functor) => functor.map(f); | |
let c2 = (f2, f1) => (x) => f2(f1(x)); | |
let c3 = (f3, f2, f1) => (x) => f3(f2(f1(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
/* | |
============================================================== | |
Clean error handling network calls using high order functions. | |
ES6 version of: | |
http://blog.carbonfive.com/2015/01/05/tidying-up-a- | |
javascript-application-with-higher-order-functions/ | |
============================================================== | |
*/ |
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 is an introduction to Transducers in Swift, inspired by | |
// Talk: https://www.youtube.com/watch?v=estNbh2TF3E | |
// Code: https://github.com/mbrandonw/learn-transducers-playground | |
// Updated with Swift 2 | |
/** | |
* Define a few test methods | |
*/ | |
/// REDUCER | |
func append <A> (xs: [A], x: A) -> [A] { return xs + [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
//-- This is an introduction to Transducers in Javascript, inspired by | |
// Talk: https://www.youtube.com/watch?v=estNbh2TF3E | |
// Code: https://github.com/mbrandonw/learn-transducers-playground | |
//-- Let's start by defining some reusable functions | |
// Mappers // A => B | |
square = (n) => n * n | |
incr = (n) => n + 1 | |
// Filterers // A => Bool |
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
typealias VoidFuncType = () -> Void | |
typealias BoolFuncType = () -> Bool | |
/** | |
IF/ELSE STATEMENT | |
*/ | |
typealias ElseIfType = (Bool, VoidFuncType) -> IfElse | |
typealias ElseType = (VoidFuncType) -> Void | |
struct IfElse { |
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
# functional waterfall method | |
waterfall = (scope) -> deploy(test(develop(design(analyse(scope))))) | |
# or | |
waterfall = (scope) -> compose(deploy, test, develop, design, analyse)(scope) | |
# or | |
waterfall = (scope) -> scope.analyse().design().develop().test().deploy() |
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
# | |
# FP solve the Change Problem | |
# eg. myChange = calcChange(cost, myPayment) | |
# | |
# Used in fold() to build change object | |
# Should be nested in calcChange, but is lifted for cleanliness | |
coinAccStructure = (acc, coin) -> | |
change = acc["payment"] | |
acc[coin] = change % coin |
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
#-- CONTENT | |
$ -> | |
___ '' | |
___ ' ███████╗██╗ ██╗███╗ ██╗ ██████╗████████╗██╗ ██████╗ ███╗ ██╗ █████╗ ██╗' | |
___ ' ██╔════╝██║ ██║████╗ ██║██╔════╝╚══██╔══╝██║██╔═══██╗████╗ ██║██╔══██╗██║' | |
___ ' █████╗ ██║ ██║██╔██╗ ██║██║ ██║ ██║██║ ██║██╔██╗ ██║███████║██║' | |
___ ' ██╔══╝ ██║ ██║██║╚██╗██║██║ ██║ ██║██║ ██║██║╚██╗██║██╔══██║██║' | |
___ ' ██║ ╚██████╔╝██║ ╚████║╚██████╗ ██║ ██║╚██████╔╝██║ ╚████║██║ ██║███████╗' | |
___ ' ╚═╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚═╝ ╚═╝╚══════╝' |