Is it possible to express the following code in such a way that the map and null skipping is expressed in one call?
list.map(_.accept(this, arg).asInstanceOf[T]).filter(_ != null)
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.
or alternatively, if you like, (though this will be converted more or less to your original expression)
Using
collectwould be possible but it would likely callaccepttwice on most arguments because of theisDefinedAttest of the partial function:One would need to use some memoising (or smart extractors) to avoid this.