Can I hide a method in Scala?

Last night, at some unpleasant hour, we celebrated our fifth instance of bug tracking due to the behavior of String.split , for example. in

 output split '\n' map processRow 

The problem is that if output empty, split will give you one line, an empty line that processRow probably won't like.

It is easy enough to increment String using the split0 method (we have), which returns an empty array if the string is empty, but we continue to forget that split has such a behavior that it is not a valid inverse mkString . Soooo, five bites of this dog is enough - we would like to hide split and force ourselves to choose between split0 and split1 . Is this possible in Scala?

+2
source share
1 answer

As you say, processRow will not like the empty string, you can just do it.

 output split '\n' filter(_.nonEmpty) map processRow 

You also have other handy features found in scala.collection.immutable.StringLike , such as StringLike.stripLineEnd , although this only separates the end-of-line character.

0
source

Source: https://habr.com/ru/post/976862/


All Articles