This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Payment makePayment(Money const& money, FromAccount const& from, ToAccount const& to) { | |
// ... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Payment makePayment(Money const& money, Account const& from, Account const& to) { | |
// ... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for (auto const& pair : map) { | |
auto const& key = pair.first; | |
auto const& value = pair.second; | |
//... do something with the key and value | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
summary :: Payment -> String | |
summary Payment { amount = amount_, from = from_, to = to_ } = | |
join " " ["Transfered", show (value amount_), currency amount_, "from", from_, "to", to_] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
summary :: Payment -> String | |
summary (Payment amount_ from_ to_) = | |
join " " ["Transfered", show (value amount_), currency amount_, "from", from_, "to", to_] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Payment { | |
Money m_amount; | |
Account m_from; | |
Account m_to; | |
}; | |
// Pattern matching against a custom structure | |
Payment payment = ...; | |
auto [amount, from, to] = payment; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for (auto const& [key, value] : map) { | |
//... do something with the key and value | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data Payment = Payment | |
{ amount :: Money | |
, from :: Account | |
, to :: Account | |
, date :: Timestamp | |
} | |
summary :: Payment -> String | |
summary (Payment amount_ from_ to_) = -- Does not compile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data Payment = Payment | |
{ amount :: Money | |
, to :: Account | |
, from :: Account | |
} | |
summary :: Payment -> String | |
summary (Payment amount_ from_ to_) = -- From and to are inverted now |