

Return the first element can throw an exception if the Seq is empty Return the first element that matches the predicate p Return all elements that do not match the predicate p

Return all elements that match the predicate p Return all elements except the last n elementsĭrop the first sequence of elements that matches the predicate p Return all elements after the first n elements Return a new sequence with no duplicate elements These methods let you “remove” elements during this process: Method
#Photoninja seq does not work how to#
Instead, you describe how to remove elements as you assign the results to a new collection. Filtering methods (how to “remove” elements from an Seq)Ī Seq is an immutable sequence, so you don’t remove elements from a Seq. Therefore, with +: and ++:, these methods comes from the Seq that’s on the right of the method name. The correct technical way to think about this is that a Scala method name that ends with the : character is right-associative, meaning that the method comes from the variable on the right side of the expression. I use that as a way to remember these methods. Note that during these operations the : character is always next to the old (original) sequence. Seq is immutable, so in all of the examples that follow you need to assign the result of the operation shown to a new variable, like this: A LinearSeq provides fast access only to the first element via head, but also has a fast tail operation.”Īlso, please see the “Seq is not Vector” section at the end of this post, because as that name implies, Seq behaves differently than Vector in almost all of these examples. An IndexedSeq provides fast random-access of elements and a fast length operation. “ Seq has two principal subtraits, IndexedSeq and LinearSeq, which give different guarantees for performance.

#Photoninja seq does not work code#
Important note about Seq, IndexedSeq, and LinearSeqĪs an important note, I use Seq in the following examples to keep things simple, but in your code you should be more precise and use IndexedSeq or LinearSeq where appropriate. Summary: This page contains many examples of how to use the methods on the Scala Seq class, including map, filter, foldLeft, reduceLeft, and many more.
