# How can i modify a tuple in sway?

**URL:** <https://forum.fuel.network/t/how-can-i-modify-a-tuple-in-sway/2948>\
**Category:** Sway\
**Created:** [July 28, 2023, 12:44pm UTC](https://forum.fuel.network/t/how-can-i-modify-a-tuple-in-sway/2948 "2023-07-28T12:44:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![carlos](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@carlos](https://forum.fuel.network/u/carlos)\
**Post date:** [July 28, 2023, 12:44pm UTC](https://forum.fuel.network/t/how-can-i-modify-a-tuple-in-sway/2948/1 "2023-07-28T12:44:15Z")

</div>

Hi. A simple question. How can i append, pop, insert to an existing tuple ? I presume the tuple is not static (as in the sway docs it is mentioned that arrays are).

---

<div class="post-metadata">

**Author:** ![calldelegation](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/calldelegation/32/1484_2.png) [@calldelegation](https://forum.fuel.network/u/calldelegation)\
**Post date:** [July 28, 2023, 8:20pm UTC](https://forum.fuel.network/t/how-can-i-modify-a-tuple-in-sway/2948/2 "2023-07-28T20:20:33Z")

</div>

Hey @carlos! [Tuples](https://fuellabs.github.io/sway/v0.42.0/book/basics/structs_tuples_and_enums.html#tuples) in Sway are **static length type** so to answer your question you cannot execute those actions.

---

<div class="post-metadata">

**Author:** ![carlos](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@carlos](https://forum.fuel.network/u/carlos)\
**Post date:** [July 30, 2023, 11:45am UTC](https://forum.fuel.network/t/how-can-i-modify-a-tuple-in-sway/2948/4 "2023-07-30T11:45:22Z")

</div>

Or use a vector instead.

Question. How can i remove an element in a vector ? Is it storage.v.remove(index) ?

---

<div class="post-metadata">

**Author:** ![calldelegation](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/calldelegation/32/1484_2.png) [@calldelegation](https://forum.fuel.network/u/calldelegation)\
**Post date:** [July 31, 2023, 12:58am UTC](https://forum.fuel.network/t/how-can-i-modify-a-tuple-in-sway/2948/5 "2023-07-31T00:58:07Z")

</div>

Yup @carlos specifically for `remove` you can refer to the documentation [here](https://github.com/FuelLabs/sway/blob/master/sway-lib-std/src/storage/storage_vec.sw#L172-L197). Take a look at the rest of the functions on that file to see all the manipulations you can do with vecs.

Heres an example for you  
Note that I am using the latest version of the toolchain

```auto
active toolchain
-----------------
latest-aarch64-apple-darwin (default)
  forc : 0.42.0
    - forc-client
      - forc-deploy : 0.42.0
      - forc-run : 0.42.0
    - forc-doc : 0.42.0
    - forc-explore : 0.28.1
    - forc-fmt : 0.42.0
    - forc-index : 0.17.3
    - forc-lsp : 0.42.0
    - forc-tx : 0.42.0
    - forc-wallet : 0.2.3
  fuel-core : 0.18.3
  fuel-indexer : 0.17.3

fuels versions
---------------
forc : 0.43
forc-wallet : 0.43.0

```

```auto
contract;

use std::storage::storage_vec::*;

storage {
    my_vec: StorageVec<u64> = StorageVec {},
}

abi MyContract {
    #[storage(read, write)]
    fn push_function(value: u64);

    #[storage(read, write)]
    fn remove_function(index: u64) -> u64;
}

impl MyContract for Contract {
    #[storage(read, write)]
    fn push_function(value: u64) {
        storage.my_vec.push(value);
    }

    #[storage(read, write)]
    fn remove_function(index: u64) -> u64 {
        return storage.my_vec.remove(index); 
        // Manipulating vecs (.pop(), .push(), .get(), .remove() etc.)
        // https://github.com/FuelLabs/sway/blob/master/sway-lib-std/src/storage/storage_vec.sw
    }
}

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex022/uploads/fuel/original/2X/5/57d5a345cc15a64b636e0d56e042857f8a0e80b1.png) [@system](https://forum.fuel.network/u/system)\
**Post date:** [August 20, 2023, 8:59pm UTC](https://forum.fuel.network/t/how-can-i-modify-a-tuple-in-sway/2948/6 "2023-08-20T20:59:03Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
