|
| 1 | +/* |
| 2 | + * Scala (https://www.scala-lang.org) |
| 3 | + * |
| 4 | + * Copyright EPFL and Lightbend, Inc. |
| 5 | + * |
| 6 | + * Licensed under Apache License 2.0 |
| 7 | + * (http://www.apache.org/licenses/LICENSE-2.0). |
| 8 | + * |
| 9 | + * See the NOTICE file distributed with this work for |
| 10 | + * additional information regarding copyright ownership. |
| 11 | + */ |
| 12 | + |
| 13 | +package scala.collection |
| 14 | + |
| 15 | +/** A template trait that contains just the `map`, `flatMap`, `foreach` and `withFilter` methods |
| 16 | + * of trait `Iterable`. |
| 17 | + * |
| 18 | + * @tparam A Element type (e.g. `Int`) |
| 19 | + * @tparam CC Collection type constructor (e.g. `List`) |
| 20 | + * |
| 21 | + * @define coll collection |
| 22 | + */ |
| 23 | +@SerialVersionUID(3L) |
| 24 | +abstract class WithFilter[+A, +CC[_]] extends Serializable { |
| 25 | + |
| 26 | + /** Builds a new collection by applying a function to all elements of the |
| 27 | + * `filtered` outer $coll. |
| 28 | + * |
| 29 | + * @param f the function to apply to each element. |
| 30 | + * @tparam B the element type of the returned collection. |
| 31 | + * @return a new $coll resulting from applying |
| 32 | + * the given function `f` to each element of the filtered outer $coll |
| 33 | + * and collecting the results. |
| 34 | + */ |
| 35 | + def map[B](f: A => B): CC[B] |
| 36 | + |
| 37 | + /** Builds a new collection by applying a function to all elements of the |
| 38 | + * `filtered` outer $coll containing this `WithFilter` instance that satisfy |
| 39 | + * |
| 40 | + * @param f the function to apply to each element. |
| 41 | + * @tparam B the element type of the returned collection. |
| 42 | + * @return a new $coll resulting from applying |
| 43 | + * the given collection-valued function `f` to each element |
| 44 | + * of the filtered outer $coll and |
| 45 | + * concatenating the results. |
| 46 | + */ |
| 47 | + def flatMap[B](f: A => IterableOnce[B]): CC[B] |
| 48 | + |
| 49 | + /** Applies a function `f` to all elements of the `filtered` outer $coll. |
| 50 | + * |
| 51 | + * @param f the function that is applied for its side-effect to every element. |
| 52 | + * The result of function `f` is discarded. |
| 53 | + * |
| 54 | + * @tparam U the type parameter describing the result of function `f`. |
| 55 | + * This result will always be ignored. Typically `U` is `Unit`, |
| 56 | + * but this is not necessary. |
| 57 | + */ |
| 58 | + def foreach[U](f: A => U): Unit |
| 59 | + |
| 60 | + /** Further refines the filter for this `filtered` $coll. |
| 61 | + * |
| 62 | + * @param q the predicate used to test elements. |
| 63 | + * @return an object of class `WithFilter`, which supports |
| 64 | + * `map`, `flatMap`, `foreach`, and `withFilter` operations. |
| 65 | + * All these operations apply to those elements of this $coll which |
| 66 | + * also satisfy both `p` and `q` predicates. |
| 67 | + */ |
| 68 | + def withFilter(q: A => Boolean): WithFilter[A, CC] |
| 69 | + |
| 70 | +} |
0 commit comments