title: How to effectively get indices of 1s for given binary string using Scala?
body: <p>Suppose we have a binary string such as <code>10010010</code>.</p>
  
  <p>All I want is a function returning indices of <code>1</code>s for that string:</p>
  
  <pre><code>indicesOfOnes("10010010") -&gt; List(0, 3, 6)
  indicesOfOnes("0") -&gt; List()
  </code></pre>
  
  <p>And what I implemented is:</p>
  
  <pre><code>def indicesOfOnes(bs: String): List[Int] = {
    val lb = ListBuffer[Int]()
    bs.zipWithIndex.foreach { case (v, i) =&gt;
      if (v == '1') {
        lb += i
      }
    }
    lb.toList
  }
  </code></pre>
  
  <p>This works, but I think there're much better (more functional) ways to do this job. Any advices would be appreciated.</p>