@solana/functional
Advanced tools
Comparing version 2.0.0-experimental.819a6f7 to 2.0.0-experimental.8245fa6
{ | ||
"name": "@solana/functional", | ||
"version": "2.0.0-experimental.819a6f7", | ||
"version": "2.0.0-experimental.8245fa6", | ||
"description": "Functional JavaScript helpers", | ||
@@ -50,4 +50,4 @@ "exports": { | ||
"@solana/eslint-config-solana": "^1.0.2", | ||
"@swc/jest": "^0.2.28", | ||
"@types/jest": "^29.5.5", | ||
"@swc/jest": "^0.2.29", | ||
"@types/jest": "^29.5.6", | ||
"@typescript-eslint/eslint-plugin": "^6.3.0", | ||
@@ -59,3 +59,3 @@ "@typescript-eslint/parser": "^6.3.0", | ||
"jest": "^29.7.0", | ||
"jest-runner-eslint": "^2.1.0", | ||
"jest-runner-eslint": "^2.1.2", | ||
"jest-runner-prettier": "^1.0.0", | ||
@@ -62,0 +62,0 @@ "prettier": "^2.8", |
@@ -24,2 +24,27 @@ [![npm][npm-image]][npm-url] | ||
`pipe`: A functional utility function for piping a value through various functions | ||
### `pipe()` | ||
Until the [pipe operator](https://github.com/tc39/proposal-pipeline-operator) becomes part of JavaScript you can use this utility to create pipelines. | ||
```ts | ||
const add = (a, b) => a + b; | ||
const add10 = x => add(x, 10); | ||
const add100 = x => add(x, 100); | ||
const sum = pipe(1, add10, add100); | ||
sum === 111; // true | ||
``` | ||
A pipeline is one solution to performing consecutive operations on a value using functions, such as you would when building a transaction. | ||
```ts | ||
const transferTransaction = pipe( | ||
// The result of the first expression... | ||
createTransaction({ version: 0 }), | ||
// ...gets passed as the sole argument to the next function in the pipeline. | ||
tx => setTransactionFeePayer(myAddress, tx), | ||
// The return value of that function gets passed to the next... | ||
tx => setTransactionLifetimeUsingBlockhash(latestBlockhash, tx), | ||
// ...and so on. | ||
tx => appendTransactionInstruction(createTransferInstruction(myAddress, toAddress, amountInLamports), tx) | ||
); | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
50
33243
19