I implemented simple unapplySeq that extracts elements of filepath to sequence:
object PathSequence {
def unapplySeq(path: Path): Seq[String] =
if (path == null || path.getFileName == null) Seq.empty
else path.getFileName.toString +: unapplySeq(path.getParent)
}
After runing it like this:
val path = Path.of("C:/Users/WIN10/IdeaProjects/LearningSandbox/src/worksheet/resources/AddTwoNumbers.java")
val PathSequence(first, second, third, _*) = path
I get an error: Star pattern must correspond with varargs or unapplySeq.
unapplySeq is implemented correctly here, the result is List(AddTwoNumbers.java, resources, worksheet, src, LearningSandbox, IdeaProjects, WIN10, Users)
How to set first, second and third variables to first three elements of result sequence?