@solana/functional 2.0.0-experimental.f6adea2 → 2.0.0-experimental.fbd3974

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +26 -1
  3. package/package.json +7 -7
package/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2018 Solana Labs, Inc
1
+ Copyright (c) 2023 Solana Labs, Inc
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
package/README.md CHANGED
@@ -21,4 +21,29 @@ is also exported as part of the Solana JavaScript SDK
21
21
 
22
22
  ## Functions
23
23
 
24
- `pipe`: A functional utility function for piping a value through various functions
24
+ ### `pipe()`
25
+
26
+ Until the [pipe operator](https://github.com/tc39/proposal-pipeline-operator) becomes part of JavaScript you can use this utility to create pipelines.
27
+
28
+ ```ts
29
+ const add = (a, b) => a + b;
30
+ const add10 = x => add(x, 10);
31
+ const add100 = x => add(x, 100);
32
+ const sum = pipe(1, add10, add100);
33
+ sum === 111; // true
34
+ ```
35
+
36
+ A pipeline is one solution to performing consecutive operations on a value using functions, such as you would when building a transaction.
37
+
38
+ ```ts
39
+ const transferTransaction = pipe(
40
+ // The result of the first expression...
41
+ createTransaction({ version: 0 }),
42
+ // ...gets passed as the sole argument to the next function in the pipeline.
43
+ tx => setTransactionFeePayer(myAddress, tx),
44
+ // The return value of that function gets passed to the next...
45
+ tx => setTransactionLifetimeUsingBlockhash(latestBlockhash, tx),
46
+ // ...and so on.
47
+ tx => appendTransactionInstruction(createTransferInstruction(myAddress, toAddress, amountInLamports), tx)
48
+ );
49
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solana/functional",
3
- "version": "2.0.0-experimental.f6adea2",
3
+ "version": "2.0.0-experimental.fbd3974",
4
4
  "description": "Functional JavaScript helpers",
5
5
  "exports": {
6
6
  "browser": {
@@ -47,15 +47,15 @@
47
47
  ],
48
48
  "devDependencies": {
49
49
  "@solana/eslint-config-solana": "^1.0.2",
50
- "@swc/jest": "^0.2.28",
51
- "@types/jest": "^29.5.5",
50
+ "@swc/jest": "^0.2.29",
51
+ "@types/jest": "^29.5.6",
52
52
  "@typescript-eslint/eslint-plugin": "^6.3.0",
53
53
  "@typescript-eslint/parser": "^6.3.0",
54
54
  "agadoo": "^3.0.0",
55
55
  "eslint": "^8.45.0",
56
56
  "eslint-plugin-sort-keys-fix": "^1.1.2",
57
57
  "jest": "^29.7.0",
58
- "jest-runner-eslint": "^2.1.0",
58
+ "jest-runner-eslint": "^2.1.2",
59
59
  "jest-runner-prettier": "^1.0.0",
60
60
  "prettier": "^2.8",
61
61
  "tsup": "7.2.0",
@@ -79,12 +79,12 @@
79
79
  "compile:typedefs": "tsc -p ./tsconfig.declarations.json",
80
80
  "dev": "jest -c node_modules/test-config/jest-dev.config.ts --rootDir . --watch",
81
81
  "publish-packages": "pnpm publish --tag experimental --access public --no-git-checks",
82
- "style:fix": "pnpm eslint --fix src/* && pnpm prettier -w src/*",
82
+ "style:fix": "pnpm eslint --fix src/* && pnpm prettier -w src/* package.json",
83
83
  "test:lint": "jest -c node_modules/test-config/jest-lint.config.ts --rootDir . --silent",
84
84
  "test:prettier": "jest -c node_modules/test-config/jest-prettier.config.ts --rootDir . --silent",
85
85
  "test:treeshakability:browser": "agadoo dist/index.browser.js",
86
- "test:treeshakability:native": "agadoo dist/index.node.js",
87
- "test:treeshakability:node": "agadoo dist/index.native.js",
86
+ "test:treeshakability:native": "agadoo dist/index.native.js",
87
+ "test:treeshakability:node": "agadoo dist/index.node.js",
88
88
  "test:typecheck": "tsc --noEmit",
89
89
  "test:unit:browser": "jest -c node_modules/test-config/jest-unit.config.browser.ts --rootDir . --silent",
90
90
  "test:unit:node": "jest -c node_modules/test-config/jest-unit.config.node.ts --rootDir . --silent"