PageRenderTime 11ms CodeModel.GetById 1ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/core/src/main/scala/scalaz/Index.scala

http://github.com/scalaz/scalaz
Scala | 35 lines | 12 code | 7 blank | 16 comment | 0 complexity | 5609350ac6517eedd61f9f603e7b8573 MD5 | raw file
 1package scalaz
 2
 3////
 4/**
 5 * Random access through an integer index.
 6 */
 7////
 8@deprecated("Index is deprecated, use Foldable#index instead", "7.1")
 9trait Index[F[_]]  { self =>
10  ////
11  /**
12   * @return the element at index `i` in a `Some`, or `None` if the given index falls outside of the range
13   */
14  def index[A](fa: F[A], i: Int): Option[A]
15
16  /**
17   * @return the element at index `i`, or `default` if the given index falls outside of the range
18   */
19  def indexOr[A](fa: F[A], default: => A, i: Int): A =
20    index(fa, i) getOrElse default
21
22  // derived functions
23
24  ////
25  val indexSyntax = new scalaz.syntax.IndexSyntax[F] { def F = Index.this }
26}
27
28@deprecated("Index is deprecated, use Foldable#index instead", "7.1")
29object Index {
30  @inline def apply[F[_]](implicit F: Index[F]): Index[F] = F
31
32  ////
33
34  ////
35}