Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def select(l : List[T], pred : T => Boolean): Option[(T, List[T])] = {
- type Discarded = List[T]
- type Remainings = List[T]
- def aux : (Discarded, Remainings) => Option[(T, List[T])] = {
- case (_, List()) => None
- case (ds, c :: tl) =>
- if(pred(c)) Some((c, ds ::: tl ))
- else aux(c :: ds, tl)
- }
- aux(List(), l)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement