You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to scala-functional
Hi all,
I'm working through chapter 4 and have implemented filter like this:
def filter(f: A =>Boolean):Option[A]=this map(f) match { caseSome(true)=>this case _ =>None }
but the answer key has it like this:
def filter(f: A =>Boolean):Option[A]=this match { caseSome(a)if f(a)=>this case _ =>None }
Is there something inefficient/wrong about the way I've done it or is this just one of the possible implementations?
Thanks!
gjk
pagoda_5b
unread,
Apr 23, 2018, 9:45:44 AM4/23/18
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to scala-functional
possibly your implementation will need to make one additional call after pattern matching... but I don't know enough about the internals to tell if there's some rewrite rule to optimize it away (I doubt so).
In any case I wouldn't worry too much, the result should be correct anyway