Skip to content

Instantly share code, notes, and snippets.

🔊
writing

Jesse Warden JesterXL

🔊
writing
Block or report user

Report or block JesterXL

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
@JesterXL
JesterXL / fizzbuzz-1.js
Last active Aug 17, 2019
FizzBuzz solutions in JavaScript and Elm.
View fizzbuzz-1.js
// JavaScript
const fizzAndOrNotBuzz = i => {
switch(true) {
case i % 15 === 0: return 'FizzBuzz'
case i % 5 === 0: return 'Buzz'
case i % 3 === 0: return 'Fizz'
default: return i
}
}
View apigateway.json
{ resource: '/test-delete-me',
path: '/test-delete-me',
httpMethod: 'GET',
headers:
{ accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'en-US,en;q=0.9,es;q=0.8',
'cache-control': 'max-age=0',
Host: 'o8ai4pej00.execute-api.us-east-1.amazonaws.com',
'upgrade-insecure-requests': '1',
@JesterXL
JesterXL / validations-snippet.js
Last active Mar 3, 2019
Example of nested Arrow functions.
View validations-snippet.js
'use strict'
const Validation = require('folktale/validation')
const { Success, Failure } = Validation
const {
isString,
some,
identity,
inRange,
@JesterXL
JesterXL / what-is-a-partial-application.md
Last active Dec 18, 2018
A quick primer on what is a partial application. (I threw this together for a friend. If you want something more thorough, then read this link: https://jesterxl.github.io/real-world-functional-programming-book/ )
View what-is-a-partial-application.md

Hard to understand without mastering pure functions, but ok.

tl;dr;

Partial Application is a function where some or all of the arguments are packed inside, ready to go and it's just waiting for a few more before the main function is invoked. They're like functions that have default arguments, but are pure functions with a fixed amount of parameters.

Basic Arguments

The function below pings google.com: const pingGoogle = () => fetch('http://google.com'). If it resolves, Google is there and your computer can talk to the internets. If it throws an error, your computer is probably having wireless trouble.

View imports.js
const { map, nth, filter, getOr, set, startCase, get, flow, isEqual, rearg, identity, curry } = require('lodash/fp')
const R = require('ramda')
const { invoker, apply } = R
View newnew.js
const parseHumans = flow([
JSON.parse,
listToPeople,
filterHumans,
formatNames
])
View compose.js
const parseHumans = jsonString => flow([
JSON.parse,
listToPeople,
filterHumans,
formatNames
])(jsonString)
View composeold.js
const parseHumans = jsonString =>
formatNames(
filterHumans(
listToPeople(
JSON.parse(jsonString)
)
)
)
View formatwhoa.js
const getName = get('name')
const setName = set('name')
const getFixedName = flow([getName, startCase])
const nameAndPerson = [{f: getFixedName}, {f: identity}]
const callF = invoker(1, 'f')
const flipMap = curry(rearg([1, 0], map))
const mapNameAndPerson = flipMap(nameAndPerson)
const getFixedNameAndPerson = flow([callF, mapNameAndPerson])
const setNameWithPersonNameAndPerson = apply(setName)
const mapFormatNames = flow([getFixedNameAndPerson, setNameWithPersonNameAndPerson])
You can’t perform that action at this time.