[FIXED] ein rechtsassoziativer dreifacher Doppelpunktoperator

Ausgabe

Obwohl ein dreifacher Doppelpunkt ein rechtsassoziativer Operator ist, sagt das folgende Ergebnis, dass er nicht wahr ist, oder?

List(3, 4, 5) ::: List(18, 19, 20) //> List[Int] = List(3, 4, 5, 18, 19, 20)

Aus meiner Sicht sollte das Ergebnis lauten, List(18, 19, 20, 3, 4, 5)da es dasselbe ist wie zu sagen:

List(18, 19, 20).:::(List(3, 4, 5))

Verstehe ich die Definition von richtig-assoziativ falsch?

Lösung

Aus den Dokumenten:

def :::(prefix: List[A]): List[A]
[use case] Adds the elements of a given list in front of this list.

Beispiel:

List(1, 2) ::: List(3, 4) = List(3, 4).:::(List(1, 2)) = List(1, 2, 3, 4)
prefix  - The list elements to prepend.
returns - a list resulting from the concatenation of the given list prefix and this list.

Das sagt alles. Was die rechtsassoziativen Operationen betrifft, haben Sie Recht.


Beantwortet von –
4lex1v


Antwort geprüft von –
Terry (FixError Volunteer)

0 Shares:
Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like