Skip to content

Instantly share code, notes, and snippets.

David Chambers davidchambers

Block or report user

Report or block davidchambers

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
davidchambers / dataTransform.js
Created Nov 14, 2017 — forked from josete89/dataTransform.js
Data mapping with sanctuary
View dataTransform.js
'use strict';
const R = require('ramda');
const S = require('sanctuary');
const data = {
id: 1,
orderName: 'Order from spain',
teamName: 'Portland penguins',
View shapes.js
// This file demonstrates a simpler approach to the problem posed in
// <>.
// Note that it's possible to define a parametrically polymorphic `move`
// function by using a `Shape s` constraint. On the other hand it is not
// possible to define a parametrically polymorphic `area` function since
// circles and rectangles require different logic.
// One could solve this problem by defining a type representative for each
// shape type, which would provide a suitable `area` function (`Z.of` takes


Write a function of type String -> Integer. The input may or may not be a valid JSON string. If it is valid, the resulting JavaScript value is expected to be an object, but may not be. If it is an object, it is expected to have a foo property whose value is expected to be an object, but may not be. This value is expected to have a bar property which is expected to be an object with a baz property whose value is expected to be an array of strings. Each of these strings is expected to be a hex representation of an integer (e.g. 0xFF). If every element of the array meets this expectation, the

View toc.awk
function drop(n) {
s = ""
for (i = n + 1; i <= NF; i += 1) { s = s (s == "" ? "" : " ") $i }
return s
/^ *\/\/\. ##/ {
indent = substr($2, 2) # reduce indentation by one level
gsub(/#/, " ", indent)
href = tolower(drop(2))
davidchambers /
Created Jun 2, 2016
Quick introduction to chaining monads from a pull request review
var convertPercentage = function(percentage) {
  if (percentage == null) {
    return null;
  } else {
    return parseFloat(percentage.replace(/[^-\d.]/g, ''));
View Main.hs
data Action = Coin | Turn deriving Show
data Locked = Locked | Unlocked deriving Show
data State = State { locked :: Locked, coins :: Int, gumballs :: Int } deriving Show
update :: Action -> State -> State
update Coin s@(State { locked = Locked, gumballs = g }) | g == 0 = s
update Coin s@(State { locked = Locked, coins = c }) = s { locked = Unlocked, coins = c + 1 }
update Turn s@(State { locked = Unlocked, gumballs = g }) = s { locked = Locked, gumballs = g - 1 }
update _ s = s
davidchambers / io.js
Last active Sep 26, 2015
Sketch of possible (synchronous) IO and AsyncIO types in JavaScript
View io.js
'use strict';
const fs = require('fs');
const R = require('ramda');
const S = require('sanctuary');
// unit :: ()
const unit = void 0;


Player Points
David 9
Darryn 6
Matt 3
Koray 3

Round 1


Function composition has one huge benefit over chaining APIs: it allows any combination of JavaScript functions to be stuck together to form a pipeline. One could create a pipeline involving a function from library A, a function from library B, a function from library C, and a built-in function. With a chaining API one is restricted to the set of functions available on the object facilitating the chaining.

I found this to be a problem when using Underscore. This would be fine for a pipeline comprised solely of Underscore functions (represented here by lower-case identifiers):

View Match.purs
findX :: (MatchObj -> Maybe MatchObj) -> [String] -> Maybe MatchObj
findX matcher words = head xs
xs = do len <- length words .. 1
idx <- 0 .. length words - len
let m = matcher { before: take idx words
, group: (drop idx >>> take len) words
, after: drop (idx + len) words
, matches: defaultTransaction
, context: []
You can’t perform that action at this time.