scala 2.9부터 List 객체의 remove 메소드가 사라졌다. Immutable 객체에 remove()가 어색했던 것 같다.
http://www.scala-lang.org/files/archive/api/2.9.0/#scala.collection.immutable.List
2.8 버전에는 deprecated된 http://www.scala-lang.org/api/2.8.2/의 List의 remove 메소드를 확인할 수 있다.
defremove (p: (A) ⇒ Boolean) : List[A]
스칼라 2.11로 테스트 해보면 다음과 같다.
scala> thrill.remove(s=>s.length ==4)
<console>:13: error: value remove is not a member of List[String]
thrill.remove(s=>s.length ==4)
^
scala> thrill.filterNot(s=>s.length==4)
res13: List[String] = List(aa, bb)
scala> thrill.filterNot(s=>s.length==2)
res14: List[String] = List()
참고로 ListBuffer에는 remove()가 존재한다. Buffer는 문맥에 맞게 제공하고 있다.
http://www.scala-lang.org/api/current/#scala.collection.mutable.ListBuffer
defremove(n: Int): A
Removes the element on a given index position.
defremove(n: Int, count: Int): Unit
Removes a given number of elements on a given index position.
def--=(xs: TraversableOnce[A]): ListBuffer.this.type
Removes all elements produced by an iterator from this shrinkable collection.
def-=(elem: A): ListBuffer.this.type
Remove a single element from this buffer.
def-=(elem1: A, elem2: A, elems: A*): ListBuffer.this.type
Removes two or more elements from this shrinkable collection.
스칼라 2.11로 테스트 해보면 다음과 같다.
scala> import scala.collection.mutable.ListBuffer
import scala.collection.mutable.ListBuffer
scala> var thrill = new ListBuffer[String]()
thrill: scala.collection.mutable.ListBuffer[String] = ListBuffer()
scala> thrill += "aaa"
res0: scala.collection.mutable.ListBuffer[String] = ListBuffer(aaa)
scala> thrill += "bbb"
res1: scala.collection.mutable.ListBuffer[String] = ListBuffer(aaa, bbb)
scala> thrill.filter(s => s.length == 2)
res4: scala.collection.mutable.ListBuffer[String] = ListBuffer()
scala> thrill.filter(s => s.length == 3)
res5: scala.collection.mutable.ListBuffer[String] = ListBuffer(aaa, bbb)
scala> thrill.remove(1)
res6: String = bbb
scala> thrill -= "bbb"
res7: scala.collection.mutable.ListBuffer[String] = ListBuffer(aaa)
'scala' 카테고리의 다른 글
[scala] =과 함수 선언 (0) | 2016.03.23 |
---|---|
[Scala] List의 sort는 deprecated, sortWith, sortBy, sorted 활용 예시 (0) | 2016.03.22 |
scala + scalatra + gradle (0) | 2015.11.30 |
[scalatra] scalate 에러 - java.lang.NoSuchMethodError: scala.tools.nsc.Global$gen$.mkBlock (0) | 2015.11.30 |
[spring boot] scala와 gradle 연동시 cool swapping (live reload) 되게 하기 (with intellij idea 14, 15) (0) | 2015.10.28 |
deprecated:
use
filterNot' instead