scala pattern mathing. What is this matching now -
/ ** (**) Continuous duplicate pack of list elements in sub-listists. If there are repeated elements in a list then they should be kept in separate Upanishads. Example: Scala & gt; Pack (list ('a,' a, 'a,' a, b, c, c, a, a, d, ee, ee, e)) res0: list [list [symbol]] = list (list List ('A', 'A', List 'D'), List ('E', 'A', 'A', 'A', A), List ('B'), List ('C', C) E, 'E,' E)) * / For the general case of this type:
object matchTest1 application {def matchTest (x: int ) Expands: string = x match {case 1 = & gt; "One" case 2 = & gt; "Two" case _ = & gt; "Many"} println (matchTest (3))} I know that it is trying to match x with pattern. But as an example below, what is it getting? Resolve similar to
// 1- My solution / ** * recursive P8 solution * / def pack (Input: list [any]): [list [any]] = { Diff Comp (L: List [Anyone], Last: Any: Last List: List [Anyone]): List [List [Any]] = {l Match {Case Neil = & gt; List [list [any]] (final list) case head :: tail if head == finalem => COMP (tail, head, head :: last list) case head :: tail if previous list == blue = gt; COMP (Tail, Head, Head :: Nil) Case Head :: Tail = & gt; LastList :: comp (tail, head, head :: zero)}} comp (input, zero, zero)} thanks
This checks list [any] for: // Is it a List below? Case Neil = & gt; ... // Is it not empty and the first thing (head) does the 'last Eelam' equal? Case head :: tail if head == last eel => ... // Is it not empty but the final list is empty? Case head :: tail if previous list == blue = gt; ... // head in every case case: tail = & gt; Typically head :: tail mails in the list head (first object) and a tail The tail should be an empty list, the tail can be an empty list, it means [1] and < Code> [1, 2] will be from both head :: tail , while [] match zero only.
Comments
Post a Comment