Nim Programming Cookbook // Data structures and Algorithms

Nim provides a variety of useful data structures such as arrays, sequences, sets, strings, tuples, tables. We will look at strings in a later chapter.

Tuples

Unpacking a tuple into separate variables

Problem

You have a tuple of N-elements that you want to unpack into N seperate variables.

Solution

let address = ("Royal Rd", "Kingville", 11234)
let (s,c,z) = address
echo s
echo c
echo z


Practical uses:

import os
let
  path = "/usr/local/bin/6m"
  (dir, name, ext) = splitFile(path)
echo dir
echo name
echo ext