Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8" ></meta>
        <title>WithIndex.scala</title>
        <script type="text/javascript" src="jquery-all.js"></script>
        <script type="text/javascript" src="linked.js"></script>
        <link rel="stylesheet" type="text/css" href="style.css" title="Style"></link>
    </head>
    <body>
        <pre>
<span class="keyword">package</span> iarray

<span class="keyword">import</span> scala.collection.generic.CanBuildFrom

<span class="keyword">final</span> <span class="keyword">class</span> <a title="class WithIndex[A] extends AnyRef" id="iarray;WithIndex">WithIndex</a><span class="delimiter">[</span><a title="" id="iarray;WithIndex;A">A</a><span class="delimiter">]</span><a href="#iarray;WithIndex" title="iarray.WithIndex[A]" class="delimiter">(</a><span class="keyword">private</span> <span class="keyword">val</span> <a title="Array[AnyRef]" id="iarray;WithIndex.self">self</a>: <span title="Array[AnyRef]">Array</span><span class="delimiter">[</span>AnyRef<span class="delimiter">]</span><span class="delimiter">)</span> <span class="delimiter">{</span>
  <span class="keyword">def</span> <a title="[B](f: (A, Int) =&gt; B)iarray.IArray[B]" id="iarray;WithIndex.map">map</a><span class="delimiter">[</span><a title="" id="iarray;WithIndex.map;B">B</a><span class="delimiter">]</span><span class="delimiter">(</span><a title="(A, Int) =&gt; B" id="iarray;WithIndex.map.f">f</a>: <span class="delimiter">(</span>A, Int<span class="delimiter">)</span> =&gt; B<span class="delimiter">)</span>: <a href="IArray.scala.html#iarray;IArray" title="iarray.IArray[B]">IArray</a><span class="delimiter">[</span>B<span class="delimiter">]</span> = <span class="delimiter">{</span>
    <span class="keyword">var</span> <a title="Int" id="iarray;WithIndex.map.i">i</a> = <span title="Int(0)" class="int">0</span>
    <span class="keyword">val</span> <a title="Array[AnyRef]" id="iarray;WithIndex.map.array">array</a> = <span title="Array[AnyRef]" class="keyword">new</span> <span title="Array[AnyRef]">Array</span><span class="delimiter">[</span>AnyRef<span class="delimiter">]</span><span class="delimiter">(</span><a href="#iarray;WithIndex.self" title="=&gt; Array[AnyRef]">self</a>.<span title="=&gt; Int">length</span><span class="delimiter">)</span>
    <span title="Unit" class="keyword">while</span><span class="delimiter">(</span><a href="#iarray;WithIndex.map.i" title="Int">i</a> <span title="(x: Int)Boolean">&lt;</span> <a href="#iarray;WithIndex.self" title="=&gt; Array[AnyRef]">self</a>.<span title="=&gt; Int">length</span><span class="delimiter">)</span><a href="#iarray;WithIndex.map.while$1" title="()Unit" class="delimiter">{</a>
      <a href="#iarray;WithIndex.map.array" title="(i: Int, x: AnyRef)Unit">array</a><span class="delimiter">(</span><a href="#iarray;WithIndex.map.i" title="Int">i</a><span class="delimiter">)</span> = <a href="#iarray;WithIndex.map.f" title="(v1: A, v2: Int)B">f</a><span class="delimiter">(</span><a href="#iarray;WithIndex.self" title="(i: Int)AnyRef">self</a><span class="delimiter">(</span><a href="#iarray;WithIndex.map.i" title="Int">i</a><span class="delimiter">)</span>.<span title="[T0]=&gt; T0">asInstanceOf</span><span title="A" class="delimiter">[</span><a href="#iarray;WithIndex;A" title="A">A</a><span class="delimiter">]</span>, <a href="#iarray;WithIndex.map.i" title="Int">i</a><span class="delimiter">)</span>.<span title="[T0]=&gt; T0">asInstanceOf</span><span title="AnyRef" class="delimiter">[</span><span title="AnyRef">AnyRef</span><span class="delimiter">]</span>
      <a href="#iarray;WithIndex.map.i" title="Int">i</a> <span title="(x: Int)Int">+=</span> <span title="Int(1)" class="int">1</span>
    <span class="delimiter">}</span>
    <span title="iarray.IArray[B]" class="keyword">new</span> <a href="IArray.scala.html#iarray;IArray" title="iarray.IArray[B]">IArray</a><span class="delimiter">(</span><a href="#iarray;WithIndex.map.array" title="Array[AnyRef]">array</a><span class="delimiter">)</span>
  <span class="delimiter">}</span>

  <span class="keyword">def</span> <a title="[U](f: (A, Int) =&gt; U)Unit" id="iarray;WithIndex.foreach">foreach</a><span class="delimiter">[</span><a title="" id="iarray;WithIndex.foreach;U">U</a><span class="delimiter">]</span><span class="delimiter">(</span><a title="(A, Int) =&gt; U" id="iarray;WithIndex.foreach.f">f</a>: <span class="delimiter">(</span>A, Int<span class="delimiter">)</span> =&gt; U<span class="delimiter">)</span>: <span title="Unit">Unit</span> = <span class="delimiter">{</span>
    <span class="keyword">var</span> <a title="Int" id="iarray;WithIndex.foreach.i">i</a> = <span title="Int(0)" class="int">0</span>
    <span title="Unit" class="keyword">while</span><span class="delimiter">(</span><a href="#iarray;WithIndex.foreach.i" title="Int">i</a> <span title="(x: Int)Boolean">&lt;</span> <a href="#iarray;WithIndex.self" title="=&gt; Array[AnyRef]">self</a>.<span title="=&gt; Int">length</span><span class="delimiter">)</span><a href="#iarray;WithIndex.foreach.while$2" title="()Unit" class="delimiter">{</a>
      <a href="#iarray;WithIndex.foreach.f" title="(v1: A, v2: Int)U">f</a><span class="delimiter">(</span><a href="#iarray;WithIndex.self" title="(i: Int)AnyRef">self</a><span class="delimiter">(</span><a href="#iarray;WithIndex.foreach.i" title="Int">i</a><span class="delimiter">)</span>.<span title="[T0]=&gt; T0">asInstanceOf</span><span title="A" class="delimiter">[</span><a href="#iarray;WithIndex;A" title="A">A</a><span class="delimiter">]</span>, <a href="#iarray;WithIndex.foreach.i" title="Int">i</a><span class="delimiter">)</span>
      <a href="#iarray;WithIndex.foreach.i" title="Int">i</a> <span title="(x: Int)Int">+=</span> <span title="Int(1)" class="int">1</span>
    <span class="delimiter">}</span>
  <span class="delimiter">}</span>

  <span class="keyword">def</span> <a title="[F[_]](implicit C: scala.collection.generic.CanBuildFrom[Nothing,(A, Int),F[(A, Int)]])F[(A, Int)]" id="iarray;WithIndex.to">to</a><span class="delimiter">[</span><a title="[_]" id="iarray;WithIndex.to;F">F</a><span class="delimiter">[</span><a title="" id="iarray;WithIndex.to;F;_">_</a><span class="delimiter">]</span><span class="delimiter">]</span><span class="delimiter">(</span><span class="keyword">implicit</span> <a title="scala.collection.generic.CanBuildFrom[Nothing,(A, Int),F[(A, Int)]]" id="iarray;WithIndex.to.C">C</a>: <span title="scala.collection.generic.CanBuildFrom[Nothing,(A, Int),F[(A, Int)]]">CanBuildFrom</span><span class="delimiter">[</span>Nothing, <span class="delimiter">(</span>A, Int<span class="delimiter">)</span>, F<span class="delimiter">[</span><span class="delimiter">(</span>A, Int<span class="delimiter">)</span><span class="delimiter">]</span><span class="delimiter">]</span><span class="delimiter">)</span>: <a href="#iarray;WithIndex.to;F" title="F[(A, Int)]">F</a><span class="delimiter">[</span><span class="delimiter">(</span>A, Int<span class="delimiter">)</span><span class="delimiter">]</span> = <span class="delimiter">{</span>
    <span class="keyword">var</span> <a title="Int" id="iarray;WithIndex.to.i">i</a> = <span title="Int(0)" class="int">0</span>
    <span class="keyword">val</span> <a title="scala.collection.mutable.Builder[(A, Int),F[(A, Int)]]" id="iarray;WithIndex.to.buf">buf</a> = <a href="#iarray;WithIndex.to.C" title="()scala.collection.mutable.Builder[(A, Int),F[(A, Int)]]">C</a><span class="delimiter">(</span><span class="delimiter">)</span>
    <span title="Unit" class="keyword">while</span><span class="delimiter">(</span><a href="#iarray;WithIndex.to.i" title="Int">i</a> <span title="(x: Int)Boolean">&lt;</span> <a href="#iarray;WithIndex.self" title="=&gt; Array[AnyRef]">self</a>.<span title="=&gt; Int">length</span><span class="delimiter">)</span><a href="#iarray;WithIndex.to.while$3" title="()Unit" class="delimiter">{</a>
      <a href="#iarray;WithIndex.to.buf" title="scala.collection.mutable.Builder[(A, Int),F[(A, Int)]]">buf</a> <span title="(elem: (A, Int))buf.type">+=</span> <span class="delimiter">(</span><span title="(_1: A, _2: Int)(A, Int)" class="delimiter">(</span><a href="#iarray;WithIndex.self" title="(i: Int)AnyRef">self</a><span class="delimiter">(</span><a href="#iarray;WithIndex.to.i" title="Int">i</a><span class="delimiter">)</span>.<span title="[T0]=&gt; T0">asInstanceOf</span><span title="A" class="delimiter">[</span><a href="#iarray;WithIndex;A" title="A">A</a><span class="delimiter">]</span>, <a href="#iarray;WithIndex.to.i" title="Int">i</a><span class="delimiter">)</span><span class="delimiter">)</span>
      <a href="#iarray;WithIndex.to.i" title="Int">i</a> <span title="(x: Int)Int">+=</span> <span title="Int(1)" class="int">1</span>
    <span class="delimiter">}</span>
    <a href="#iarray;WithIndex.to.buf" title="scala.collection.mutable.Builder[(A, Int),F[(A, Int)]]">buf</a>.<span title="()F[(A, Int)]">result</span>
  <span class="delimiter">}</span>

<span class="delimiter">}</span>



        </pre>
    </body>
</html>
New to GrepCode? Check out our FAQ X