@solana/functional
Advanced tools
Comparing version 2.0.0-experimental.782d1ea to 2.0.0-experimental.7a1b905
@@ -7,3 +7,1 @@ // src/pipe.ts | ||
export { pipe }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.node.js.map |
{ | ||
"name": "@solana/functional", | ||
"version": "2.0.0-experimental.782d1ea", | ||
"version": "2.0.0-experimental.7a1b905", | ||
"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", | ||
@@ -84,3 +84,3 @@ "prettier": "^2.8", | ||
"publish-packages": "pnpm publish --tag experimental --access public --no-git-checks", | ||
"style:fix": "pnpm eslint --fix src/* && pnpm prettier -w src/*", | ||
"style:fix": "pnpm eslint --fix src/* && pnpm prettier -w src/* package.json", | ||
"test:lint": "jest -c node_modules/test-config/jest-lint.config.ts --rootDir . --silent", | ||
@@ -87,0 +87,0 @@ "test:prettier": "jest -c node_modules/test-config/jest-prettier.config.ts --rootDir . --silent", |
@@ -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) | ||
); | ||
``` |
Sorry, the diff of this file is not supported yet
37208
21
50
95