Logo

Programming-Idioms

  • JS
  • Python

Idiom #126 Multiple return values

Write a function foo that returns a string and a boolean value.

foo = lambda: ('abc', True)
def foo():
    return 'string', True
const foo = () => ['string', true];
const foo = () => ({string: 'string', bool: true})

Usage:
let {string: a, bool: b} = foo ()
#include <stdbool.h>
typedef struct {
    const char * const a;
    const bool b;
} RetStringBool;

RetStringBool foo() {
    return (RetStringBool) {.a = "Hello", .b = true};
}

New implementation...
< >
MLKo