Ivan Čukić

Qt Functional [2]

Qt Functional

A teaser, again. This time with std:: stuff instead of Qt. Why? Because I can :)

list <string> inputList;

// ... do something to the inputList ...

string first, second;
list <string> outputList;

(QfTuple | first, second, outputList)
                            = inputList.begin();

// or just (and it is safer)

(QfTuple | first, second, outputList)
                            = inputList;

// now, the variables first and second contain
// the first two elements of the inputList, and
// outputList contains the rest

Qt Functional

Edit: Sorry for bumping this, WordPress seems to think changing a post title should publish it in RSS again

Qt Functional

QfStringList sentence;

sentence << "TZU"
         << "Anticipate"
         << "the"
         << "difficult"
         << "by"
         << "managing"
         << "the"
         << "easy";

sentence
    .foldLeft(Functions::sum);
// "TZUAnticipatethedifficultbymanagingtheeasy"

sentence
    .map(QF_FUNCTION(QString, toUpper()));
// ("TZU", "ANTICIPATE", "THE", "DIFFICULT",
//  "BY", "MANAGING", "THE", "EASY")

sentence
    .map(QF_FUNCTION(QString, length()));
// (3, 10, 3, 9, 2, 8, 3, 4)

sentence
    .map(QF_FUNCTION(QString, length()))
    .foldLeft(Functions::sum);
// 42