@solana/functional
This package contains generalized functional helpers and functional helpers
specific to Solana application components. It can be used standalone, but it
is also exported as part of the Solana JavaScript SDK
@solana/web3.js@experimental
.
Functions
pipe()
Until the pipe operator becomes part of JavaScript you can use this utility to create pipelines.
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;
A pipeline is one solution to performing consecutive operations on a value using functions, such as you would when building a transaction.
const transferTransaction = pipe(
createTransaction({ version: 0 }),
tx => setTransactionFeePayer(myAddress, tx),
tx => setTransactionLifetimeUsingBlockhash(latestBlockhash, tx),
tx => appendTransactionInstruction(createTransferInstruction(myAddress, toAddress, amountInLamports), tx)
);