I hereby claim:
- I am danielfgray on github.
- I am danielfgray (https://keybase.io/danielfgray) on keybase.
- I have a public key ASCZBK5f_xYF8vv7J8Iszrg7lNorAHLcO7_UZ3WCVk9k5go
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
---
layout: post
title: Functional programming: currying and partial application
category: computers
tags: [programming, javascript, fp]
date: 2017/08/23
---
An explanation of currying and partial application using JavaScript
const { curry } = require('ramda') | |
const { Observable } = require('rxjs/Observable') | |
require('rxjs/add/observable/interval') | |
require('rxjs/add/operator/concatMap') | |
require('rxjs/add/operator/takeWhile') | |
require('rxjs/add/operator/reduce') | |
const request$ = curry((base, header, method, endpoint, query = {}) => | |
Observable.defer(() => request(method, `${base}${endpoint}`).set(header).query(query)) | |
.map(x => x.body)) |
git log --graph --oneline --decorate --all --color=always | | |
fzf --ansi +s --preview='git show --color=always {2}' \ | |
--bind='pgdn:preview-page-down' \ | |
--bind='pgup:preview-page-up' \ | |
--bind='enter:execute:git show --color=always {2} | less -R' \ | |
--bind='ctrl-x:execute:git checkout {2} .' |
#!/usr/bin/env node | |
const { spawn } = require('child_process') | |
const { Observable } = require('rxjs') | |
const { | |
curry, | |
head, | |
identity, | |
join, | |
map, | |
memoize, |
const { spawn } = require('child_process') | |
const readToEnd = stream => | |
new Promise(((resolve, reject) => { | |
const parts = [] | |
stream.on('error', reject) | |
stream.on('data', part => parts.push(part)) | |
stream.on('end', () => resolve(Buffer.concat(parts))) | |
})) |
const net = require('net') | |
const { Observable } = require('rxjs') | |
const R = require('ramda') | |
const { | |
T, | |
concat, | |
cond, | |
drop, | |
equals, |
-- Standard awesome library | |
gears = require('gears') | |
awful = require('awful') | |
require('awful.autofocus') | |
-- Widget and layout library | |
wibox = require('wibox') | |
-- Theme handling library | |
beautiful = require('beautiful') | |
-- Notification library | |
naughty = require('naughty') |
const search = curry((pattern, str) => $( | |
pattern, | |
match(/!?(".*?"|\S+)/g), | |
reject(test(/^\W*$/)), | |
map(replace(/"(.*)"/, '$1')), | |
partition(startsWith('!')), | |
over(lensIndex(0), ifElse(isEmpty, T, $(drop(1), map(includesI), complement(anyPass)))), | |
over(lensIndex(1), $(map(includesI), allPass)), | |
([n, p]) => and(n, p, str), | |
)) |