Solidity Tips – How to Ignore Return Values

solidity

I have a function which returns two uint values:

function unclaimedCollateralRewardAndDebt() public view returns(uint, uint)

in most cases I use both returned values but sometime I need only one. Is there a way to ignore one of the returned values like in GoLang?

// getting both values
(uint unclaimedCollateral, uint unclaimedDebt) = unclaimedCollateralRewardAndDebt();
// get only first value
(_, uint unclaimedDebt) = unclaimedCollateralRewardAndDebt();
// get only second value
(uint unclaimedCollateral, _) = unclaimedCollateralRewardAndDebt();

Best Answer

// get only first value
(, uint unclaimedDebt) = unclaimedCollateralRewardAndDebt();
// get only second value
(uint unclaimedCollateral,) = unclaimedCollateralRewardAndDebt();

should work