Skip to content

Instantly share code, notes, and snippets.

Avatar
🔥
<(^^<) <(^^)> (>^^)>

Daniel Bolívar ddanielbee

🔥
<(^^<) <(^^)> (>^^)>
View GitHub Profile
View fantasy-maybe.js
// Utils
const fantasyConcat = (semiOne, semiTwo) => {
if (
semiOne.instances &&
semiTwo.instances &&
semiOne.instances.includes("Semigroup") &&
semiTwo.instances.includes("Semigroup")
)
return semiOne.concat(semiTwo);
@ddanielbee
ddanielbee / nestedObjects.js
Created May 17, 2018
Nested Object accessing without Maybe, maybe.
View nestedObjects.js
const NOTHING = {};
const safeProperty = (obj, propertyName) => (obj[propertyName] ? obj[propertyName] : NOTHING);
const recurProperties = (obj, ...propertyNames) =>
propertyNames.reduce(
(accValue, currentProperty) =>
accValue[currentProperty] ? accValue[currentProperty] : NOTHING,
obj
);
@ddanielbee
ddanielbee / stringManip.js
Created May 7, 2018
Property Based Testing String stuff
View stringManip.js
const jsc = require("jsverify");
// Write a function that:
// Takes an array of strings
// Removes all instances of a dash character (-)
// Makes sure concatenating the strings will result in a string
// shorter than 200 characters
// (by removing all extra fluff from the tail)
// Makes all strings lowercase
// Returns an array of the resulting strings.
@ddanielbee
ddanielbee / functorProperties.js
Last active May 4, 2018
Functor Laws property based testing
View functorProperties.js
const jsc = require("jsverify");
// Necessary Utils
const id = x => x;
const compose = (...fns) => x => fns.reduceRight((v, f) => f(v), x);
// Functor Properties
const functorIdentity = f => f.fmap(id).toString() === f.toString();
@ddanielbee
ddanielbee / maybe.js
Created Mar 8, 2018
Javascript Maybe playground
View maybe.js
const Nothing = () => ({
isJust: () => false,
fold: (b, f) => b,
inspect: () => `Nothing`
});
const Just = x => ({
isJust: () => true,
fold: (b, f) => f(x),
inspect: () => `Just${x}`