[Solved] [Sophia] How to unpack tuple

Why can’t I unpack tuple in a way specified by this documentation?

For example this does not compile:

let t = ("ak_2mwRmUeYmfuW93ti9HMSUJzCk1EYcQEfikVSzgo6k2VghsWhgU", 100)
let (addr, amount) = t

Parse error, unexpected token ‘(’ in second line.

I’m using [email protected] which runs aeternity/aeternity nodes (docker hub).

@philipp.chain should be able to help here. I will ping him.

2 Likes

Hey, you can only do pattern matching using switch, so

switch(tuple)
  (first, second) => ???
1 Like

Also I just noticed that the documentation you referenced is very outdated as it was created based on reasonml when Sophia wasn’t finished yet, we’ll fix this (cc @pegah.chain)

1 Like

For the classical 2-tuple, the easy way to do this now is actually:

let x = Pair.fst(("Hello" * "World"))

x will be hello. Same thing with Pair.snd() , which will return the second element of the tuple.

1 Like

@nikitafuchs.chain also the initial example is now supported, no need for additional function calls

2 Likes