Skip to content

Example Use Cases

J. S. Choi edited this page Dec 8, 2018 · 18 revisions

An unsorted, incomplete list of real-world use cases, for each of the four pipeline proposals.

F# Pipeline

Straight-forward Cases

// 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
}

Quick Debugging

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)

Usage with Ternary

// 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 }

Usage with const

// 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]

Functional Updates

// Before:
return Event.create(
  Object.assign(attrs, { parent_id: parentId, status: 'draft' })
)

// After:
return Object.assign(attrs, { parent_id: parentId, status: 'draft' })
  |> Event.create

Smart Pipline

See the Core Proposal real-world examples.

Clone this wiki locally
You can’t perform that action at this time.