Skip to content

Instantly share code, notes, and snippets.

View ddanielbee's full-sized avatar
🔥
<(^^<) <(^^)> (>^^)>

Daniel Bolívar ddanielbee

🔥
<(^^<) <(^^)> (>^^)>
View GitHub Profile
@ddanielbee
ddanielbee / maybe.js
Created March 8, 2018 15:49
Javascript Maybe playground
const Nothing = () => ({
isJust: () => false,
fold: (b, f) => b,
inspect: () => `Nothing`
});
const Just = x => ({
isJust: () => true,
fold: (b, f) => f(x),
inspect: () => `Just${x}`
@ddanielbee
ddanielbee / functorProperties.js
Last active May 4, 2018 14:54
Functor Laws property based testing
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 / stringManip.js
Created May 7, 2018 14:55
Property Based Testing String stuff
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 / nestedObjects.js
Created May 17, 2018 15:05
Nested Object accessing without Maybe, maybe.
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
);
// Utils
const fantasyConcat = (semiOne, semiTwo) => {
if (
semiOne.instances &&
semiTwo.instances &&
semiOne.instances.includes("Semigroup") &&
semiTwo.instances.includes("Semigroup")
)
return semiOne.concat(semiTwo);