When does using if-let rather than let make code look better and does it have any performance impact?
When does using if-let rather than let make code look better and does it
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I guess if-let should be used when you’d like to reference an
ifcondition’s value in the “then” part of the code:i.e. instead of
you write:
which is a little neater, and saves you indenting a further level. As far as efficiency goes, you can see that the macro expansion doesn’t add much overhead:
This also illustrates that the binding can’t be referred to in the “
else” part of the code.