unique method

List<AccountMeta> unique()

Remove all duplicate accounts, meaning accounts having the same public key. Signers and/or writeable accounts are picked over non-signers and non-writeable.

Implementation

List<AccountMeta> unique() =>
    fold<List<AccountMeta>>([], (List<AccountMeta> list, AccountMeta item) {
      final index = list.indexOfPubKey(item.pubKey);
      if (index == -1) {
        return [...list, item];
      }

      // Keep then one of the two that is either a signer or
      // a writeable account
      list[index] = item.mergeWith(list[index]);

      return list;
    });