Skip to content

Instantly share code, notes, and snippets.

Payment makePayment(Money const& money, FromAccount const& from, ToAccount const& to) {
// ...
}
Payment makePayment(Money const& money, Account const& from, Account const& to) {
// ...
}
for (auto const& pair : map) {
auto const& key = pair.first;
auto const& value = pair.second;
//... do something with the key and value
}
summary :: Payment -> String
summary Payment { amount = amount_, from = from_, to = to_ } =
join " " ["Transfered", show (value amount_), currency amount_, "from", from_, "to", to_]
summary :: Payment -> String
summary (Payment amount_ from_ to_) =
join " " ["Transfered", show (value amount_), currency amount_, "from", from_, "to", to_]
// Thanks to auto, we can grow our tuple and it will not break
auto tuple = returns_a_tuple();
auto x = std::get<0>(tuple);
auto y = std::get<1>(tuple);
// With pattern matching the following will break upon growing the tuple
auto [x, y] = returns_a_tuple();
struct Payment {
Money m_amount;
Account m_from;
Account m_to;
};
// Pattern matching against a custom structure
Payment payment = ...;
auto [amount, from, to] = payment;
for (auto const& [key, value] : map) {
//... do something with the key and value
}
data Payment = Payment
{ amount :: Money
, from :: Account
, to :: Account
, date :: Timestamp
}
summary :: Payment -> String
summary (Payment amount_ from_ to_) = -- Does not compile
data Payment = Payment
{ amount :: Money
, to :: Account
, from :: Account
}
summary :: Payment -> String
summary (Payment amount_ from_ to_) = -- From and to are inverted now