Skip to content

paccalin/scala

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TD2 Listes et fonctions sur les listes

Le but de ce TD est d'implémenter quelque methodes

  • Une qui permet de calculer la somme de tous les éléments d’une liste de nombres.
  • Une qui renvoie le plus grand élément contenu dans une liste de nombres.
  • Une qui renverse une liste
  • Une qui fusionne 2 listes sans redondance

Installation

  • Télécharger le ZIP
  • Décompresser le
  • Importer le comme 'existing Project' dans eclipse ( File --> import --> General --> existing projects into workspace)
  • Pour lancer les tests unitaire du projet, cliquer droit sur le fichier de tests ' ( Run As --> Scala Junit Test)

Liste des fichiers

src
|- main
|  |- scala
|  |  |- common
|  |  |  |- package.scala
|  |  |- exemple
|  |  |  |- lists.scala          // Méthodes à implémenter
|- test
|  |- scala
|  |  |- exemple
|  |  |  |- listsTests.scala     // Tests à implémenter

Exercise

  • Dissection des listes
    • Exécutez ses différentes instructions, et regardez les différents types retourne
     val list = List(1,2,3)
     list.tail
     list.init
     list.head
     list.last
    • Implémenter les methodes du fichier lists.scala
    • Implémenter et/ou corriger les fonctions de test du fichier listsUnitTests

Scala doc List

List()Creates an empty List
NilCreates an empty List
List("Cool", "tools", "rule")Creates a new List[String] with the three values "Cool", "tools", and "rule"
val thrill = "Will" :: "fill" :: "until" :: NilCreates a new List[String] with the three values "Will", "fill", and "until"
thrill(2)Returns the 2nd element (zero based) of the thrill List (returns "until")
thrill.drop(2)Returns the thrill List without its first 2 elements (returns List("until"))
thrill.foreach(s => print(s))Executes the print statement on each of the Strings in the thrill List (prints "Willfilluntil")
thrill.foreach(print)Same as the previous, but more concise (also prints "Willfilluntil")
thrill.headReturns the first element in the thrill List (returns "Will")
thrill.initReturns a List of all but the last element in the thrill List (returns List("Will", "fill"))
thrill.isEmptyIndicates whether the thrill List is empty (returns false)
thrill.lastReturns the last element in the thrill List (returns "until")
thrill.lengthReturns the number of elements in the thrill List (returns 3)
thrill.tailReturns the thrill List minus its first element (returns List("fill", "until"))

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages