-
Notifications
You must be signed in to change notification settings - Fork 107
Example use cases
J. S. Choi edited this page Sep 24, 2021
·
1 revision
This is an out-of-date, old, unsorted, incomplete list of real-world use cases, for each of the four pipeline proposals.
See the examples from the explainer.
// Before
if ( cache && localStorage.getItem(endpoint) ) {
return m.prop( JSON.parse( localStorage.get(endpoint) ) )
}
// After
if ( cache && localStorage.getItem(endpoint) ) {
return endpoint
|> localStorage.get
|> JSON.parse
|> m.prop
}
// Alternatively
if ( cache && localStorage.getItem(endpoint) ) {
return endpoint |> localStorage.get |> JSON.parse |> m.prop
}
Easy to type & delete logging, assuming you have a friendly log function on hand.
function log (message) {
return function (subject) {
console.log(message, subject)
return subject
}
}
// Before
unify( env, constraints.map( c => t.substitute(subst, c) ) )
// After
constraints.map( c => t.substitute(subst, c) )
|> unify.papp(env)
// After, with debugging
constraints.map( c => t.substitute(subst, c) )
|> log("Constraints:")
|> unify.papp(env)
// Before
return item[item.length-1] === '/'
? Array.flattenOneLevel(
await crawlFolder(githubToken, course_name_id, Git.fileTreeUrl(course_name_id, item))
)
: { type: 'file', name: Path.basename(item), path: item }
// After
return item[item.length-1] === '/'
? Git.fileTreeUrl(course_name_id, item)
|> url => crawlFolder(githubToken, course_name_id, url)
|> await
|> Array.flattenOneLevel
: { type: 'file', name: Path.basename(item), path: item }
// Before
let items = base64ToJSON(response.data.content)
items = Array.isArray(items) ? items : [items]
// After
const items = base64ToJSON(response.data.content)
|> x => Array.isArray(x) ? x : [x]
// Before:
return Event.create(
Object.assign(attrs, { parent_id: parentId, status: 'draft' })
)
// After:
return Object.assign(attrs, { parent_id: parentId, status: 'draft' })
|> Event.create