Skip to content
justinmann edited this page Dec 24, 2017 · 4 revisions

To simplify storing minimally structured data, SJ supports tuple for storing and assigning data:

a : (1, "hello") // creates tuple2![i32, string]
a.item1 // gets first value in tuple -- 1
a.item2 // gets second value in tuple -- "hello"
(val:, name:) a // copies first value to val and second value to name

// One way to use tuples to make it easy to 
// return errors and results from the same function
func() {
    if somethingBad {
        (0, error("failure"))
    } else {
        (1, error.success())
    }
}

(result:, error:) func()

Clone this wiki locally