Skip to content

Instantly share code, notes, and snippets.

View anthony2025's full-sized avatar
🛵

Anthony Ascencio anthony2025

🛵
View GitHub Profile
import fp from 'lodash/fp';
const uncappedMap = fp.map.convert({ cap: false });
@anthony2025
anthony2025 / uncappedMap.js
Created April 26, 2018 19:15
provides us a fp.map with a (value, key, index) signature, super useful for objects
import fp from 'lodash/fp';
const uncappedMap = fp.map.convert({ cap: false });
const percentChance = (probability) => Math.random() <= probability
if (percentChance(0.95)) doSomething()
const unix_timestamp = js_timestamp/1000|0;
@anthony2025
anthony2025 / Link.js
Last active June 1, 2018 01:06
React-Router Link that handles falsy 'to' props and mailto links
@anthony2025
anthony2025 / conditional.js
Created June 5, 2018 17:35
for use inside compose/flow statements, branches based on a 'predicate' (more precisely just a boolean value)
export const conditional = <T>(predicate: boolean, ifTrue: T => *, ifFalse: T => *) =>
(value: T) => predicate ? ifTrue(value) : ifFalse(value);
@anthony2025
anthony2025 / mapObject.js
Created June 5, 2018 17:37
provides us a map with a (value, key, index) inner function signature
export const mapObject = R.addIndex(R.map);
@anthony2025
anthony2025 / tapAndLog.js
Created June 5, 2018 17:40
for use inside compose/flow statements, logs without disrupting the data flow
// for use inside compose/flow statements, logs without disrupting the data flow
export const tapAndLog = <T>(data: T): T => console.log('tapped', data) || data; // eslint-disable-line no-console
export const caseInsensitiveIncludes = _.curry((str1: string, str2: string): boolean =>
!!str1.match(new RegExp(str2, 'i')));
export const caseInsensitiveIncludes = _.curry((str1: string, str2: string): boolean =>
!!str1.match(new RegExp(str2, 'i')));