Skip to content

Add temp var to real-world examples #254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,10 @@ From [jquery/build/tasks/sourceMap.js][]:
// Status quo
var minLoc = Object.keys( grunt.config( "uglify.all.files" ) )[ 0 ];

// Temp vars
const files = grunt.config("uglify.all.files")
const minLoc = Object.keys(files)[0];

// With pipes
var minLoc = grunt.config('uglify.all.files') |> Object.keys(%)[0];
```
Expand All @@ -744,6 +748,11 @@ From [node/deps/npm/lib/unpublish.js][]:
// Status quo
const json = await npmFetch.json(npa(pkgs[0]).escapedName, opts);

// Temp vars
const firstPkg = pkgs[0]
const {escapedName} = npa(firstPkg)
const json = await npmFetch.json(escapedName, opts);

// With pipes
const json = pkgs[0] |> npa(%).escapedName |> await npmFetch.json(%, opts);
```
Expand All @@ -753,6 +762,11 @@ From [underscore.js][]:
// Status quo
return filter(obj, negate(cb(predicate)), context);

// Temp vars
const fn = cb(predicate)
const negatedFn = negate(fn)
return filter(obj, negatedFn, context)

// With pipes
return cb(predicate) |> _.negate(%) |> _.filter(obj, %, context);
```
Expand All @@ -762,6 +776,11 @@ From [ramda.js][].
// Status quo
return xf['@@transducer/result'](obj[methodName](bind(xf['@@transducer/step'], xf), acc));

// Temp vars
const boundStep = bind(xf['@@transducer/step'], xf)
const fn = obj[methodName](boundStep)
return xf['@@transducer/result'](fn)

// With pipes
return xf
|> bind(%['@@transducer/step'], %)
Expand All @@ -778,6 +797,14 @@ try {
return catcher.apply(this, _concat([e], arguments));
}

// Temp vars
try {
return tryer.apply(this, arguments);
} catch (e) {
const concatenated = _concat([e], arguments)
return catcher.apply(this, concatenated);
}

// With pipes: Note the visual parallelism between the two clauses.
try {
return arguments
Expand All @@ -796,6 +823,12 @@ return this.set('Link', link + Object.keys(links).map(function(rel){
return '<' + links[rel] + '>; rel="' + rel + '"';
}).join(', '));

// Temp vars
const links = Object.keys(links).map((rel) => {
return '<' + links[rel] + '>; rel="' + rel + '"';
});
return this.set('Link', link + links.join(', '))

// With pipes
return links
|> Object.keys(%).map(function (rel) {
Expand All @@ -818,6 +851,14 @@ console.log(
)
);

// Temp vars
const envvars = Object.keys(envars)
.map(envar => `${envar}=${envars[envar]}`)
.join(' ')}
const str = `$ ${envvars}`
const val = chalk.dim(str, 'node', args.join(' '))
console.log(val);

// With pipes
Object.keys(envars)
.map(envar => `${envar}=${envars[envar]}`)
Expand All @@ -832,6 +873,11 @@ From [ramda.js][].
// Status quo
return _reduce(xf(typeof fn === 'function' ? _xwrap(fn) : fn), acc, list);

// Temp vars
const fn = (typeof fn === 'function' ? _xwrap(fn) : fn)
const wrapped = xf(%)
const out = _reduce(%, acc, list);

// With pipes
return fn
|> (typeof % === 'function' ? _xwrap(%) : %)
Expand All @@ -848,6 +894,11 @@ jQuery.merge( this, jQuery.parseHTML(
true
) );

// Temp vars
const doc = context && context.nodeType ? context.ownerDocument || context : document
const parsedHtml = jQuery.parseHTML(match[1], doc, true)
const mergedHtml = jQuery.merge(parsedHtml);

// With pipes
context
|> (% && %.nodeType ? %.ownerDocument || % : document)
Expand Down