The Scala Programming Language

Web Name: The Scala Programming Language

WebSite: http://www.scala-lang.org

ID:15268

Keywords:

Scala,The,Language,

Description:

The Scala Programming Language Scala combines object-oriented and functional programming in one concise, high-level language. Scala's static types help avoid bugs in complex applications, and its JVM and JavaScript runtimes let you build high-performance systems with easy access to huge ecosystems of libraries. LEARN MORE Scala began life in 2003, created by Martin Odersky and his research group at EPFL, next to Lake Geneva and the Alps, in Lausanne, Switzerland. Scala has since grown into a mature open source programming language, used by hundreds of thousands of developers, and is developed and maintained by scores of people all over the world. Seamless Java Interop Scala runs on the JVM, so Java and Scala stacks can be freely mixed for totally seamless integration. Type Inference So the type system doesn’t feel so static. Don’t work for the type system. Let the type system work for you! Concurrency & Distribution Use data-parallel operations on collections, use actors for concurrency and distribution, or futures for asynchronous programming. class Author(val firstName: String, val lastName: String) extends Comparable[Author] { override def compareTo(that: Author) = { val lastNameComp = this.lastName compareTo that.lastName if (lastNameComp != 0) lastNameComp else this.firstName compareTo that.firstNameobject Author { def loadAuthorsFromFile(file: java.io.File): List[Author] = ???} public List Author loadAuthorsFromFile(File file) { return new ArrayList Author (asJavaCollection( Author.loadAuthorsFromFile(file))); public void sortAuthors(List Author authors) { Collections.sort(authors); public void displaySortedAuthors(File file) { List Author authors = loadAuthorsFromFile(file); sortAuthors(authors); for (Author author : authors) { System.out.println( author.lastName() + ", " + author.firstName());} Combine Scala and Java seamlessly Scala classes are ultimately JVM classes. You can create Java objects, calltheir methods and inherit from Java classes transparently from Scala.Similarly, Java code can reference Scala classes and objects.In this example, the Scala class Author implements the Javainterface Comparable T and works with JavaFiles. The Java code uses a method from the companion objectAuthor, and accesses fields of the Author class.It also uses JavaConversions to convert between Scala collectionsand Java collections. scala class Person(val name: String, val age: Int) { | override def toString = s"$name ($age)"defined class Personscala def underagePeopleNames(persons: List[Person]) = { | for (person - persons; if person.age 18) | yield person.nameunderagePeopleNames: (persons: List[Person])List[String]scala def createRandomPeople() = { | val names = List("Alice", "Bob", "Carol", | "Dave", "Eve", "Frank") | for (name - names) yield { | val age = (Random.nextGaussian()*8 + 20).toInt | new Person(name, age)createRandomPeople: ()List[Person]scala val people = createRandomPeople()people: List[Person] = List(Alice (16), Bob (16), Carol (19), Dave (18), Eve (26), Frank (11))scala underagePeopleNames(people)res1: List[String] = List(Alice, Bob, Frank) Let the compiler figure out the types for you The Scala compiler is smart about static types. Most of the time, you neednot tell it the types of your variables. Instead, its powerful type inferencewill figure them out for you.In this interactive REPL session (Read-Eval-Print-Loop), we define aclass and two functions. You can observe that the compiler infers the resulttypes of the functions automatically, as well as all the intermediate values. val x = Future { someExpensiveComputation() }val y = Future { someOtherExpensiveComputation() }val z = for (a b - y) yield a*bfor (c - z) println("Result: " + c)println("Meanwhile, the main thread goes on!") Go Concurrent or Distributed with Futures Promises In Scala, futures and promises can be used to process data asynchronously, making it easier to parallelize or even distribute your application.In this example, the Future{} construct evaluates its argument asynchronously, and returnsa handle to the asynchronous result as a Future[Int].For-comprehensions can be used to register new callbacks (to post new things to do) when the future iscompleted, i.e., when the computation is finished.And since all this is executed asynchronously, without blocking, the mainprogram thread can continue doing other work in the meantime. Traits Combine the flexibility of Java-style interfaces with the power of classes. Think principled multiple-inheritance. Pattern Matching Think “switch” on steroids. Match against class hierarchies, sequences, and more. Higher-order functions Functions are first-class objects. Compose them with guaranteed type safety. Use them anywhere, pass them to anything.In Scala, multiple traits can be mixed into a class to combine their interface and theirbehavior.Here, a StarCruiser is a Spacecraft with a CommandoBridge that knows how toengage the ship (provided a means to speed up) and a PulseEngine thatspecifies how to speed up. Switch on the structure of your data In Scala, case classes are used to represent structural datatypes. They implicitly equip the class with meaningful toString,equals and hashCode methods, as well as theability to be deconstructed with pattern matching.In this example, we define a small set of case classes that represent binarytrees of integers (the generic version is omitted for simplicity here).In inOrder, the match construct chooses the rightbranch, depending on the type of t, and at the same timedeconstructs the arguments of a Node. // Define a set of case classes for representing binary trees.sealed abstract class Treecase class Node(elem: Int, left: Tree, right: Tree) extends Treecase object Leaf extends Tree// Return the in-order traversal sequence of a given tree.def inOrder(t: Tree): List[Int] = t match { case Node(e, l, r) = inOrder(l) ::: List(e) ::: inOrder(r) case Leaf = List()} Go Functional with Higher-Order Functions In Scala, functions are values, and can be defined as anonymous functions with a concise syntax.// Partition `people` into two arrays `minors` and `adults`.// Use the anonymous function `(_.age 18)` as a predicate for partitioning.val (minors, adults) = people partition (_.age 18)List Person minors = new ArrayList Person (people.size());List Person adults = new ArrayList Person (people.size());for (Person person : people) { if (person.getAge() 18) minors.add(person); else adults.add(person);} Scastie is Scala + sbt in your browser! You can use any version of Scala, or even alternate backends such as Dotty, Scala.js, Scala Native, and Typelevel Scala. You can use any published library. You can save and share Scala programs/builds with anybody. Sphere.it Kraków, Poland 05 Oct 2020 - 06 Oct 2020 Scala Matsuri Tokyo, Japan 17 Oct 2020 - 18 Oct 2020 BeeScala Ljubljana, Slovenia 26 Nov 2020 - 28 Nov 2020 Functional Scala London, UK 03 Dec 2020 - 04 Dec 2020 Scala ecosystem The Scala Library Index (or Scaladex) is a representation of a map of all published Scala libraries. With Scaladex, a developer can now query more than 175,000 releases of Scala libraries. Scaladex is officially supported by Scala Center. BLOG One-click install for Scala Monday, June 29, 2020 Installing Scala has always been a task more challenging than necessary, with the potential to drive away beginners.Should I install Scala itself? sbt? Some other build tools? What about a better REPL like Ammonite? Oh and before all that I need to install Java?To solve this problem, the Scala Center contracted Alexandre Archambault in January 2020 to add a one-click install of Scala through coursier.For example, on Linux, all we now need is:$ curl -Lo cs https://git.io/coursier-cli-linux chmod +x cs ./cs setupwhich will install all the following software, if not yet installed:With all those installed, we are ready to go!Later, cs update can be used to update the installation.For power users, the cs setup command offers more configuration options, such as a non-interactive mode.With this new simple, all-encompassing installer, we at the Scala Center hope to significantly reduce the burden of getting started with Scala. Scala Users for general Scala questions, discussion and library announcements. Scala Contributors for Scala contributions, language evolution discussions, standard library, Scala platform evolution discussions and more.

TAGS:Scala The Language 

<<< Thank you for your visit >>>

Websites to related :
Journey Tool Kit – Just another

  Skip to secondary menu Skip to content Skip to primary sidebar Skip to footerJourney Tool KitJust another WordPress siteHomeLife ToolsTech StuffTravel

mSpy Review 2019 - Everything Yo

  mSpy Review Does It Really Work? mSpy Overview: What It Is and How It WorksmSpy is a mobile monitoring app that can be installed on your child’s phon

Cornell University Library

  Search for books, articles, databases and moreAbout this searchSearch everything Search  Ask a LibrarianHere are the kinds of questions your friends

Automotive Forums .com - Car Cha

  Start participating in our community - register now! Hi! I'd like to welcome you to AutomotiveForums.com! We have been around since the year 2000 - be

National Association of Hotel L

  HEADLINESPlease Call NAHLE at 540-743-1530 or Email: admin@nahle.org Until-Further-Notice. - Now is an Excellent Time to Prepare Yourself and be Compe

The National Archives

  Free digital downloads While our Kew site is closed, signed-in users can download digital records for free. Read about our fair use policy and why we

WorldatWork | Total Rewards - Ex

  Online EducationHelping You Shape Workplaces for Today and TomorrowStay on top of your professional development — while staying safe — with our onli

The Emmys The National Academy

  © The National Academy of Television Arts Sciences. All rights reserved. Emmy® and the Emmy® statuette are trademarks of ATAS/NATAS.

Gridiron New Jersey High School

  Official Playoff MatchupsStrength Index is Locked In, Including for Out-of-StateExplaining Strength Index and OSI2019 is HereNon-Public Finals and Bow

Newport News, VA - Official Webs

  Newport News and Volunteers of America Chesapeake & Carolinas Launch YouthBuild Program Program provides college and career readiness for young people

ads

Hot Websites