Skip to content

Instantly share code, notes, and snippets.

@lmiller1990
Created January 9, 2021 04:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lmiller1990/bfe3827e77e597cf0713087d6bc8d719 to your computer and use it in GitHub Desktop.
Save lmiller1990/bfe3827e77e597cf0713087d6bc8d719 to your computer and use it in GitHub Desktop.
Futuristic functional language for web dev
module.exports = {
plugins: [
["@babel/plugin-proposal-pipeline-operator", { "proposal": "fsharp" }],
["@babel/plugin-proposal-partial-application"]
]
}
const input = '1, 2, 3, 4 '
const Str = {
split: (...args) => String.prototype.split.call(...args),
trim: (...args) => String.prototype.trim.call(...args),
}
const Arr = {
map: (...args) => Array.prototype.map.call(...args),
reduce: (...args) => Array.prototype.reduce.call(...args),
filter: (...args) => Array.prototype.filter.call(...args),
join: (...args) => Array.prototype.join.call(...args),
length: val => val.length
}
const Num = {
parseInt: (...args) => parseInt(...args)
}
const toNumber = x => x
|> Str.trim
|> Num.parseInt
const numbers = input
|> Str.split(?, ',')
|> Arr.map(?, toNumber(?))
const negatives = Arr.filter(numbers, x => x < 0)
if (Arr.length(negatives) > 0) {
const msg = Arr.join(negatives, ',')
throw Error(`No negatives: ${msg}`)
}
numbers
|> Arr.reduce(?, (acc, curr) => acc + curr, 0)
|> console.log
Math.random() |> console.log
{
"dependencies": {
"@babel/core": "^7.12.10",
"@babel/node": "^7.12.10",
"@babel/plugin-proposal-partial-application": "^7.12.1",
"@babel/plugin-proposal-pipeline-operator": "^7.12.1",
"chokidar": "^3.5.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment