@@ -45,6 +45,19 @@ trait Coll[@specialized A] {
4545 */
4646 def apply (i : Int ): A
4747
48+ /** The element at given index or None if there is no such element. Indices start at `0`.
49+ *
50+ * @param i the index
51+ * @return the element at the given index, or None if there is no such element
52+ */
53+ def get (i : Int ): Option [A ] = {
54+ if (isDefinedAt(i)) {
55+ Some (apply(i))
56+ } else {
57+ None
58+ }
59+ }
60+
4861 /** Tests whether this $coll contains given index.
4962 *
5063 * The implementations of methods `apply` and `isDefinedAt` turn a `Coll[A]` into
@@ -76,6 +89,18 @@ trait Coll[@specialized A] {
7689 * produces a collection ((x0, y0), ..., (xK, yK)) where K = min(N, M) */
7790 def zip [@ specialized B ](ys : Coll [B ]): Coll [(A , B )]
7891
92+ /**
93+ * @return true if first elements of this collection form given `ys` collection, false otherwise.
94+ * E.g. [1,2,3] starts with [1,2]
95+ */
96+ def startsWith (ys : Coll [A ]): Boolean
97+
98+ /**
99+ * @return true if last elements of this collection form given `ys` collection, false otherwise.
100+ * E.g. [1,2,3] ends with [2,3]
101+ */
102+ def endsWith (ys : Coll [A ]): Boolean
103+
79104 /** Tests whether a predicate holds for at least one element of this collection.
80105 * @param p the predicate used to test elements.
81106 * @return `true` if the given predicate `p` is satisfied by at least one element of this collection, otherwise `false`
0 commit comments