Gathering detailed insights and metrics for fpjson-lang
Gathering detailed insights and metrics for fpjson-lang
npm install fpjson-lang
Typescript
Module System
Node Version
NPM Version
Total Downloads
9,011
Last Day
1
Last Week
18
Last Month
41
Last Year
2,118
Minified
Minified + Gzipped
Latest Version
0.1.5
Package Id
fpjson-lang@0.1.5
Unpacked Size
18.51 kB
Size
5.61 kB
File Count
6
NPM Version
8.19.3
Node Version
18.13.0
Publised On
27 Sept 2023
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
350%
18
Compared to previous week
Last month
-19.6%
41
Compared to previous month
Last year
-61.3%
2,118
Compared to previous year
FPJSON is a programming language agnostic JSON-based functional programming language.
In other words, you don't have to worry about any programming language specifications.
Instead you can just focus on building pure logics for data manipuration.
Since it's just a JSON array, it can be ported to any programming language environment.
1/* add */ 2["add", 1, 2] // = 3 3 4/* difference */ 5["difference", [1, 2, 3], [3, 4, 5]] = [1, 2] 6 7/* map */ 8[["map", ["inc"]], [1, 2, 3]] // = [4, 5, 6] 9 10/* compose */ 11[["compose", ["map", ["inc"]], ["difference"]], [1, 2, 3], [3, 4, 5]] // = [2, 3]
There are more than 250 pre-defined functions. And you can further extend that library.
For now the parser is only implemented in JavaScript and it borrows heavily from Ramda.js.
In fast, you can use most of the functions in Ramda with FPJSON.
1yarn add fpjson-lang
It couldn't be simpler.
1import fpjson from "fpjson-lang" 2 3const one_plus_two = fpjson(["add", 1, 2]) // = 3
You should familiarize yourself with Ramda which enables Haskell-like functional programming with JS. You can use most of the powerful ramda functions with point-free style in JSON.
The first element in an array is a function.
1["add", 1, 2] // add(1, 2)
To curry a function, nest it.
1[["add", 1], 2] // add(1)(2)
A function always needs to be wrapped with []
and to be the first element in the array.
1[["map", ["inc"]], [1, 2, 3]] // map(inc)([1, 2, 3])
This is an error because inc
is imterpreted as String
.
1[["map", "inc"], [1, 2, 3]] // map("inc")([1, 2, 3])
Point-free style means you cannot write something like this with the JSON format.
1sortBy((v)=> v.age)(people) // ramdajs
It's because you cannot write arbitrary JS lines such as (v)=> v.age
.
Instead, you can achieve the same using another ramda funciton prop
.
1sortBy(prop("age"), people) // ramdajs 2["sortBy",["prop", "age"], people] // FPJSON
By placing a reserved word in the first spot of an array, you can access the pre-built features.
There are just 6 of them.
To create an array of functions without executing them, place "[]"
in the first spot, otherwise the ["lte", 2]
function will be executed with ["gt", 2]
before -3
is passed.
1[["anyPass", ["[]", ["lte", 2], ["gt", 2]]], -3] // anyPass(lte(2), gt(2))(-3)
To create a type object such as Number
, Boolean
, String
, Array
, and Object
.
1["is", ["typ", "String"], "abc"] // is(String, "abc")
To create a RegExp
.
1["test", ["reg", "a", "i"], "ABC"] // test(new RegExp("a", "i"), "ABC")
Pure functional programming without any side-effects is easy to get extremely complex and entangled even for simple logics.
"let"
inserts global variables to ease up the unnecessary complexisities.
1["let", "num1", 1] // let var1 = 1
To access previously defined variables, use "$"
.
1["add", ["var", "num1"], 1] // add(num1, 1)
In practice, you need to use "let"
and "$"
in the same array.
1[["pipe", ["add", 1], ["let", "num1"], ["$", "num1"]], 1]) // = 2
Or you can pass a store object as the second argument to fpjson
.
1let vars = {} 2fpjson(["let", "num1", 1], vars) // vars = { "num1" : 1 } 3fpjson(["add", ["$", "num1"], 1], vars) // 2
var
works just like $
except that var
needs another argument to invoke.
The last argument can be anything since it will be ignored.
Note that you cannot access a new value within the same composition where it was defined.
1let vars = {} 2fpjson(["let", "num1", 1], vars) // vars = { "num1" : 1 } 3fpjson(["add", ["var", "num1", true], 1], vars) // 2
Variable names can be dinamically specified with $dynamic_path
.
1let vars = {} 2fpjson(["let", "num1", 1], vars) // vars = { "num1" : 1 } 3fpjson(["let", "ln", "num1"], vars) // vars = { "num1" : 1, "ln" : "num1" } 4fpjson(["add", ["$, "$ln"], 1], vars) // 2
Nested fields can be accessed with .
.
1let vars = {} 2fpjson(["let", "o", { num: 1 }], vars) // vars = { "o" : { "num": 1 } } 3fpjson(["var", "o.num", true ], vars) // 1
FPJSON is used to define access control rules and cron jobs in WeaveDB - Arweave-based decentralized NoSQL Database. FPJSON allows super rich and complex programming logics to be stored as JSON data on smart contracts, which opens up a whole new pradigm to dapp development.
FPJSON is also to be used for natural language generation algorithms, which will lead to the next-gen AI paradigm to revolutionize the human languages.
Learning functional programming is pretty challenging. So we created interactive tutorials and an exam to make sure you can familiarize yourself with all the core functions with ease!
Going through the tutorials will install a new framework in your brain and make you a better programmer in general even if you never need FPJSON.
It's not so much about languages, but about how your brain agnostically operates on data structures.
No vulnerabilities found.
No security vulnerabilities found.