I am reading a TSV file and I am using something like this:
< Code> Case class Entry (EntryType: Int, value: Int) def filterEntries (): For Iterator [entry] = {{line & lt; - scala.io.Source.fromFile ("filename"). GetLines ()} generated new entry (line.split ("\ T") .map (x = & gt; x.toInt))}
Now I want to filter those entries Interested, those who have entryType
are set to 0 and ignoring the lines with the number of columns more than or less than 2 (which does not match the constructor) I was thinking that an idiomatic method of obtaining it pattern Use of matching and can use the inappropriate
method in a companion object I can imagine that using only one thing .filter
result iterator.
I will also accept the solution for not including loop, but it returns
iterator [entrance]
. They should be tolerant of sneaky inputs from solutions.
This is more state-arty:
package object liner { Underlying class R (Val SC: Stringcontact) {Object R {DF Aspen Sec (S: String): Option [SEQ [string]] = Scapar.MKstringsR unplayable SEK s}}} Package liner {Case class entry (entry type) : Int, value: int) object i {def unsuitable (string): option [int] = use TRI (STII). Totation} Object Test App {DEF Line = List ("1 2", "3", "", "4 5", "Junk", "0, 100000", "6 7 8") DIT entries = Lines flatmap {case r "" \ s * $ {I (i)} (\ d +) \ s + $ {I (j)} (\ d +) \ s * "If I! = 0 = & gt; some (insertion (i, j)) case __________________________________________________ = & gt; none} console println entries}}
hopefully, regex The interpolator will soon make it into the standard distro, but it shows how easily it is up to. The f-style interpolator will allow easy extraction with the case F "$ i% d"
.
I have just started using "long wildcard" in the pattern
Comments
Post a Comment