Skip to content

Instantly share code, notes, and snippets.

View donnut's full-sized avatar

Erwin donnut

  • Amsterdam, The Netherlands
View GitHub Profile
@donnut
donnut / gist:38a090b2bce02dafbba134e088c3b9fc
Created November 4, 2016 07:53 — forked from danielgtaylor/gist:0b60c2ed1f069f118562
Moving to ES6 from CoffeeScript

Moving to ES6 from CoffeeScript

I fell in love with CoffeeScript a couple of years ago. Javascript has always seemed something of an interesting curiosity to me and I was happy to see the meteoric rise of Node.js, but coming from a background of Python I really preferred a cleaner syntax.

In any fast moving community it is inevitable that things will change, and so today we see a big shift toward ES6, the new version of Javascript. It incorporates a handful of the nicer features from CoffeeScript and is usable today through tools like Babel. Here are some of my thoughts and issues on moving away from CoffeeScript in favor of ES6.

While reading I suggest keeping open a tab to Babel's learning ES6 page. The examples there are great.

Punctuation

Holy punctuation, Batman! Say goodbye to your whitespace and hello to parenthesis, curly braces, and semicolons again. Even with the advanced ES6 syntax you'll find yourself writing a lot more punctuatio

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@donnut
donnut / unions.ts
Created February 9, 2015 10:37
unions and type guard
interface IMessage {
name: string;
}
function itemFn(pipIn: string[]) {
return pipIn;
}
function baseFn(pipIn: string) {
return [pipIn];
@donnut
donnut / index.js
Last active August 29, 2015 14:08
requirebin sketch
var R = require('ramda');
var data = [
{it: 'item2', signal: 'update', select: true},
{it: 'item1', signal: 'update', select: false}
]
console.log(R.contains({it: 'item2', signal: 'update', select: true}, data));
@donnut
donnut / currying.md
Last active October 28, 2023 17:58
TypeScript and currying

TypeScript and currying

In functional programming you often want to apply a function partly. A simple example is a function add. It would be nice if we could use add like:

var res2 = add(1, 3); // => 4

var add10To = add(10);
var res = add10To(5); // => 15
@donnut
donnut / mapping.md
Last active August 29, 2015 14:08
TypeScript and mapping

Typescript and mapping

Map takes a function and maps the content of a list to another list of the same length. We want to double the numbers in a list, using the function doubler

function doubler(x) {
    return x*2;
}
@donnut
donnut / index.js
Last active August 29, 2015 14:07
requirebin sketch
var R = require('ramda').installTo(this)
var a = {}
var b = {y: a}
var c = {z: b}
a.x = c
var refFrom = []
var refTo = []
@donnut
donnut / index.js
Last active August 29, 2015 14:07
requirebin sketch
// circular reference
var _ = require('lodash')
var c = {x:2}
var a = {x:3, c: c}
var b = {x:1, z: a}
c.p = b
var a1 = _.cloneDeep(a)
b.x = 5
@donnut
donnut / index.js
Created October 6, 2014 14:09
requirebin sketch
var R = require('ramda');
function Maybe(x) {
if (!(this instanceof Maybe)) {
return new Maybe(x);
}
this.value = x;
}
Maybe.of = function(x) {
@donnut
donnut / index.js
Created October 6, 2014 14:04
requirebin sketch
var R = require('ramda');
function Maybe(x) {
if (!(this instanceof Maybe)) {
return new Maybe(x);
}
this.value = x;
}
Maybe.of = function(x) {