I want to write a function for process sequence, like this:
def wrap[A >: Seq[_], B](seq : A)(f : () => B): Option[B] = {
if(seq.isEmpty) None
else Some(f())
}
But it doesn’t work
error:
error: value isEmpty is not a member of type parameter A
if(seq.isEmpty) None
What did I do wrong?
You don’t need to say anything about
Aat all. Just say that the first argument towrapis aSeq, then you can pass in aSeqor any subclass thereof: