Scala: Object-Oriented Meets Functional, by Iulian Dragos3Pillar Global
A presentation from Iulian Dragos of Typesafe that gives an overview of the Scala programming language. The presentation was given at a Functional Angle conference in Timisoara, Romania sponsored by 3Pillar. Iulian Dragos has been working on Scala since 2004. He currently works for Typesafe, a start-up that was co-founded by Scala’s creator, Martin Odersky.
Scala: Object-Oriented Meets Functional, by Iulian Dragos3Pillar Global
A presentation from Iulian Dragos of Typesafe that gives an overview of the Scala programming language. The presentation was given at a Functional Angle conference in Timisoara, Romania sponsored by 3Pillar. Iulian Dragos has been working on Scala since 2004. He currently works for Typesafe, a start-up that was co-founded by Scala’s creator, Martin Odersky.
Slides from my talk at the Junction (Jan 24, 2013)
Single-core performance has hit a ceiling, and building web-scale multi-core applications using imperative programming models is nightmarishly difficult. Parallel programming creates a new set of challenges, best practices and design patterns. Scala is designed to enable building scalable systems, elegantly blending functional and object oriented paradigms into an expressive and concise language, while retaining interoperability with Java. Scala is the fastest growing JVM programming language, being rapidly adopted by leading companies such as Twitter, LinkedIn and FourSquare.
This presentation provides a comprehensive overview of the language, which managed to increase type safety while feeling more dynamic, being more concise and improving readability at the same time. We will see how Scala simplifies real life problems by empowering the developer with powerful functional programming primitives, without giving up on the object oriented paradigm. The overview includes tools for multi-core programming in Scala, the type system, collection framework and domain-specific languages. We’ll explore the power of compile-time meta-programming, which is made possible by the newly released Scala 2.10, and get a glimpse into what to expect from 2.11 in 2014.
We will also see how Scala helps overcome the inherent limitations of Java, such as type erasure, array covariance and boxing overhead.
Multiple examples emphasize how Scala pushes the JVM harder than any other mainstream language through the infinite number of boilerplate busters, increased type safety and productivity boosters from a Java developer’s perspective.
Short (45 min) version of my 'Pragmatic Real-World Scala' talk. Discussing patterns and idioms discovered during 1.5 years of building a production system for finance; portfolio management and simulation.
Sets, maps and hash tables (Java Collections)Fulvio Corno
Sets, maps and hash tables in the Java Collections framework
Teaching material for the course of "Tecniche di Programmazione" at Politecnico di Torino in year 2012/2013. More information: http://bit.ly/tecn-progr
Functional Programming with JavaScriptMark Shelton
Introductory talk to using Functional Programming in Vanilla JavaScript. Includes 5 practical examples with worked solutions in ES6+, ES5, and with currying. See Github repo for more: https://github.com/fp-uwa/getting-started-javascript
Summary:
Intro to JavaScript
Developments in JavaScript
Array Functions
Currying & Closures
Useful Resources & Next Steps
Functional Programming Meetup at The University of Western Australia.
Speaker: Mark Shelton. Date: 10 November 2017.
Mark Shelton: https://markshelton.me | @marksheltonwa
Slides from my talk at the Junction (Jan 24, 2013)
Single-core performance has hit a ceiling, and building web-scale multi-core applications using imperative programming models is nightmarishly difficult. Parallel programming creates a new set of challenges, best practices and design patterns. Scala is designed to enable building scalable systems, elegantly blending functional and object oriented paradigms into an expressive and concise language, while retaining interoperability with Java. Scala is the fastest growing JVM programming language, being rapidly adopted by leading companies such as Twitter, LinkedIn and FourSquare.
This presentation provides a comprehensive overview of the language, which managed to increase type safety while feeling more dynamic, being more concise and improving readability at the same time. We will see how Scala simplifies real life problems by empowering the developer with powerful functional programming primitives, without giving up on the object oriented paradigm. The overview includes tools for multi-core programming in Scala, the type system, collection framework and domain-specific languages. We’ll explore the power of compile-time meta-programming, which is made possible by the newly released Scala 2.10, and get a glimpse into what to expect from 2.11 in 2014.
We will also see how Scala helps overcome the inherent limitations of Java, such as type erasure, array covariance and boxing overhead.
Multiple examples emphasize how Scala pushes the JVM harder than any other mainstream language through the infinite number of boilerplate busters, increased type safety and productivity boosters from a Java developer’s perspective.
Short (45 min) version of my 'Pragmatic Real-World Scala' talk. Discussing patterns and idioms discovered during 1.5 years of building a production system for finance; portfolio management and simulation.
Sets, maps and hash tables (Java Collections)Fulvio Corno
Sets, maps and hash tables in the Java Collections framework
Teaching material for the course of "Tecniche di Programmazione" at Politecnico di Torino in year 2012/2013. More information: http://bit.ly/tecn-progr
Functional Programming with JavaScriptMark Shelton
Introductory talk to using Functional Programming in Vanilla JavaScript. Includes 5 practical examples with worked solutions in ES6+, ES5, and with currying. See Github repo for more: https://github.com/fp-uwa/getting-started-javascript
Summary:
Intro to JavaScript
Developments in JavaScript
Array Functions
Currying & Closures
Useful Resources & Next Steps
Functional Programming Meetup at The University of Western Australia.
Speaker: Mark Shelton. Date: 10 November 2017.
Mark Shelton: https://markshelton.me | @marksheltonwa
Scala is an alternative JVM language with both object-oriented and functional programming paradigms. Scala development with the Java EE 7 platform is definitely possible and can be a pleasant experience. If you have uncertainty about how Scala can fit around the Java EE 7 platform, then this session aims to illustrate the huge benefit that Scala adoption can bring to the platform. Many other developers are taking advantage and the challenge of the JVM’s capability of being a vessel for multi-language programming. You no longer have to write every single project using Java, even if you like Lambdas experiences. For the developer and engineering terms that feeling a little braver than usual, Scala is attractive as it is strongly typed and lets you set the gauge on how object oriented or how functional you want to be. You will learn how to reuse the annotations and creating Scala plain object safely and concisely. This session will highlight and contrast the experience I had developing Scala solutions with Java EE, and there will be plenty of advice about using the functional programming features against the Java object oriented API.
Scala language overview
Java EE 7 architecture and design
WildFly 8 application server
Using Gradle as a build tool
How to create beans in Scala with dependency injection
JAX-RS endpoints
Servlet Endpoints
JMS Messaging
Scala adoption advice and hints for sustainable team development
JavaCro 2014 Scala and Java EE 7 Development ExperiencesPeter Pilgrim
Scala is an alternative JVM language with both object-oriented and functional programming paradigms. Scala development with the Java EE 7 platform is definitely possible and can be a pleasant experience. If you have uncertainty about how Scala can fit around the Java EE 7 platform, then this session aims to illustrate the huge benefit that Scala adoption can bring to the platform. Many other developers are taking advantage and the challenge of the JVM’s capability of being a vessel for multi-language programming. You no longer have to write every single project using Java, even if you like Lambdas experiences.
For the developer and engineering terms that feeling a little braver than usual, Scala is attractive as it is strongly typed and lets you set the gauge on how object oriented or how functional you want to be. You will learn how to reuse the annotations and creating Scala plain object safely and concisely.
This session will highlight and contrast the experience I had developing Scala solutions with Java EE, and there will be plenty of advice about using the functional programming features against the Java object oriented API.
Scala language overview
Java EE 7 architecture and design
Using Gradle as a build tool
How to create beans in Scala with dependency injection
JAX-RS endpoints
Servlet Endpoints
JMS Messaging
Scala adoption advice and hints for sustainable team development
From Java to Scala - advantages and possible risksSeniorDevOnly
Oleksii Petinov during his presentation gave the audience the overview of his vision of Scala pros and contras. In his vision Scala smoothly integrates features of object-oriented and functional languages, enabling Java and other programmers to be more productive.
There is admittedly some truth to the statement that “Scala is complex”, but the learning curve is well worth the investment.
We describe the deployment and use of Globus Compute for remote computation. This content is aimed at researchers who wish to compute on remote resources using a unified programming interface, as well as system administrators who will deploy and operate Globus Compute services on their research computing infrastructure.
Navigating the Metaverse: A Journey into Virtual Evolution"Donna Lenk
Join us for an exploration of the Metaverse's evolution, where innovation meets imagination. Discover new dimensions of virtual events, engage with thought-provoking discussions, and witness the transformative power of digital realms."
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Crescat
Crescat is industry-trusted event management software, built by event professionals for event professionals. Founded in 2017, we have three key products tailored for the live event industry.
Crescat Event for concert promoters and event agencies. Crescat Venue for music venues, conference centers, wedding venues, concert halls and more. And Crescat Festival for festivals, conferences and complex events.
With a wide range of popular features such as event scheduling, shift management, volunteer and crew coordination, artist booking and much more, Crescat is designed for customisation and ease-of-use.
Over 125,000 events have been planned in Crescat and with hundreds of customers of all shapes and sizes, from boutique event agencies through to international concert promoters, Crescat is rigged for success. What's more, we highly value feedback from our users and we are constantly improving our software with updates, new features and improvements.
If you plan events, run a venue or produce festivals and you're looking for ways to make your life easier, then we have a solution for you. Try our software for free or schedule a no-obligation demo with one of our product specialists today at crescat.io
Graspan: A Big Data System for Big Code AnalysisAftab Hussain
We built a disk-based parallel graph system, Graspan, that uses a novel edge-pair centric computation model to compute dynamic transitive closures on very large program graphs.
We implement context-sensitive pointer/alias and dataflow analyses on Graspan. An evaluation of these analyses on large codebases such as Linux shows that their Graspan implementations scale to millions of lines of code and are much simpler than their original implementations.
These analyses were used to augment the existing checkers; these augmented checkers found 132 new NULL pointer bugs and 1308 unnecessary NULL tests in Linux 4.4.0-rc5, PostgreSQL 8.3.9, and Apache httpd 2.2.18.
- Accepted in ASPLOS ‘17, Xi’an, China.
- Featured in the tutorial, Systemized Program Analyses: A Big Data Perspective on Static Analysis Scalability, ASPLOS ‘17.
- Invited for presentation at SoCal PLS ‘16.
- Invited for poster presentation at PLDI SRC ‘16.
OpenMetadata Community Meeting - 5th June 2024OpenMetadata
The OpenMetadata Community Meeting was held on June 5th, 2024. In this meeting, we discussed about the data quality capabilities that are integrated with the Incident Manager, providing a complete solution to handle your data observability needs. Watch the end-to-end demo of the data quality features.
* How to run your own data quality framework
* What is the performance impact of running data quality frameworks
* How to run the test cases in your own ETL pipelines
* How the Incident Manager is integrated
* Get notified with alerts when test cases fail
Watch the meeting recording here - https://www.youtube.com/watch?v=UbNOje0kf6E
In the ever-evolving landscape of technology, enterprise software development is undergoing a significant transformation. Traditional coding methods are being challenged by innovative no-code solutions, which promise to streamline and democratize the software development process.
This shift is particularly impactful for enterprises, which require robust, scalable, and efficient software to manage their operations. In this article, we will explore the various facets of enterprise software development with no-code solutions, examining their benefits, challenges, and the future potential they hold.
Atelier - Innover avec l’IA Générative et les graphes de connaissancesNeo4j
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Allez au-delà du battage médiatique autour de l’IA et découvrez des techniques pratiques pour utiliser l’IA de manière responsable à travers les données de votre organisation. Explorez comment utiliser les graphes de connaissances pour augmenter la précision, la transparence et la capacité d’explication dans les systèmes d’IA générative. Vous partirez avec une expérience pratique combinant les relations entre les données et les LLM pour apporter du contexte spécifique à votre domaine et améliorer votre raisonnement.
Amenez votre ordinateur portable et nous vous guiderons sur la mise en place de votre propre pile d’IA générative, en vous fournissant des exemples pratiques et codés pour démarrer en quelques minutes.
Zoom is a comprehensive platform designed to connect individuals and teams efficiently. With its user-friendly interface and powerful features, Zoom has become a go-to solution for virtual communication and collaboration. It offers a range of tools, including virtual meetings, team chat, VoIP phone systems, online whiteboards, and AI companions, to streamline workflows and enhance productivity.
Utilocate offers a comprehensive solution for locate ticket management by automating and streamlining the entire process. By integrating with Geospatial Information Systems (GIS), it provides accurate mapping and visualization of utility locations, enhancing decision-making and reducing the risk of errors. The system's advanced data analytics tools help identify trends, predict potential issues, and optimize resource allocation, making the locate ticket management process smarter and more efficient. Additionally, automated ticket management ensures consistency and reduces human error, while real-time notifications keep all relevant personnel informed and ready to respond promptly.
The system's ability to streamline workflows and automate ticket routing significantly reduces the time taken to process each ticket, making the process faster and more efficient. Mobile access allows field technicians to update ticket information on the go, ensuring that the latest information is always available and accelerating the locate process. Overall, Utilocate not only enhances the efficiency and accuracy of locate ticket management but also improves safety by minimizing the risk of utility damage through precise and timely locates.
Large Language Models and the End of ProgrammingMatt Welsh
Talk by Matt Welsh at Craft Conference 2024 on the impact that Large Language Models will have on the future of software development. In this talk, I discuss the ways in which LLMs will impact the software industry, from replacing human software developers with AI, to replacing conventional software with models that perform reasoning, computation, and problem-solving.
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Mind IT Systems
Healthcare providers often struggle with the complexities of chronic conditions and remote patient monitoring, as each patient requires personalized care and ongoing monitoring. Off-the-shelf solutions may not meet these diverse needs, leading to inefficiencies and gaps in care. It’s here, custom healthcare software offers a tailored solution, ensuring improved care and effectiveness.
AI Genie Review: World’s First Open AI WordPress Website CreatorGoogle
AI Genie Review: World’s First Open AI WordPress Website Creator
👉👉 Click Here To Get More Info 👇👇
https://sumonreview.com/ai-genie-review
AI Genie Review: Key Features
✅Creates Limitless Real-Time Unique Content, auto-publishing Posts, Pages & Images directly from Chat GPT & Open AI on WordPress in any Niche
✅First & Only Google Bard Approved Software That Publishes 100% Original, SEO Friendly Content using Open AI
✅Publish Automated Posts and Pages using AI Genie directly on Your website
✅50 DFY Websites Included Without Adding Any Images, Content Or Doing Anything Yourself
✅Integrated Chat GPT Bot gives Instant Answers on Your Website to Visitors
✅Just Enter the title, and your Content for Pages and Posts will be ready on your website
✅Automatically insert visually appealing images into posts based on keywords and titles.
✅Choose the temperature of the content and control its randomness.
✅Control the length of the content to be generated.
✅Never Worry About Paying Huge Money Monthly To Top Content Creation Platforms
✅100% Easy-to-Use, Newbie-Friendly Technology
✅30-Days Money-Back Guarantee
See My Other Reviews Article:
(1) TubeTrivia AI Review: https://sumonreview.com/tubetrivia-ai-review
(2) SocioWave Review: https://sumonreview.com/sociowave-review
(3) AI Partner & Profit Review: https://sumonreview.com/ai-partner-profit-review
(4) AI Ebook Suite Review: https://sumonreview.com/ai-ebook-suite-review
#AIGenieApp #AIGenieBonus #AIGenieBonuses #AIGenieDemo #AIGenieDownload #AIGenieLegit #AIGenieLiveDemo #AIGenieOTO #AIGeniePreview #AIGenieReview #AIGenieReviewandBonus #AIGenieScamorLegit #AIGenieSoftware #AIGenieUpgrades #AIGenieUpsells #HowDoesAlGenie #HowtoBuyAIGenie #HowtoMakeMoneywithAIGenie #MakeMoneyOnline #MakeMoneywithAIGenie
First Steps with Globus Compute Multi-User EndpointsGlobus
In this presentation we will share our experiences around getting started with the Globus Compute multi-user endpoint. Working with the Pharmacology group at the University of Auckland, we have previously written an application using Globus Compute that can offload computationally expensive steps in the researcher's workflows, which they wish to manage from their familiar Windows environments, onto the NeSI (New Zealand eScience Infrastructure) cluster. Some of the challenges we have encountered were that each researcher had to set up and manage their own single-user globus compute endpoint and that the workloads had varying resource requirements (CPUs, memory and wall time) between different runs. We hope that the multi-user endpoint will help to address these challenges and share an update on our progress here.
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...Juraj Vysvader
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I didn't get rich from it but it did have 63K downloads (powered possible tens of thousands of websites).
Software Engineering, Software Consulting, Tech Lead, Spring Boot, Spring Cloud, Spring Core, Spring JDBC, Spring Transaction, Spring MVC, OpenShift Cloud Platform, Kafka, REST, SOAP, LLD & HLD.
Do you want Software for your Business? Visit Deuglo
Deuglo has top Software Developers in India. They are experts in software development and help design and create custom Software solutions.
Deuglo follows seven steps methods for delivering their services to their customers. They called it the Software development life cycle process (SDLC).
Requirement — Collecting the Requirements is the first Phase in the SSLC process.
Feasibility Study — after completing the requirement process they move to the design phase.
Design — in this phase, they start designing the software.
Coding — when designing is completed, the developers start coding for the software.
Testing — in this phase when the coding of the software is done the testing team will start testing.
Installation — after completion of testing, the application opens to the live server and launches!
Maintenance — after completing the software development, customers start using the software.
2. About me
Software engineer, nearly 20 years now
Architect, team lead, technical PM
Telcos, startups
employee, freelancer, consultant
Java enthusiast since 1997
Scala enthusiast since 2004 (2007)
Co-author of "Steps in Scala"
Java meetup @ Thessaloniki - 2017-10-12 2
3. A very incomplete meline
2004 v1.0
2006 v2.0
2007 v2.7 (+Li web framework)
2010 v2.8 (+ScalaDays @ EPFL, 180 participants)
2011 v2.9
2012 v2.10
now v2.12 (+Java 8 interoperability)
Java meetup @ Thessaloniki - 2017-10-12 3
4. Main ideas ‐ Why Scala?
Synthesis of OOP and FP
Being scalable
Programming in the small vs programming in
the large
Provide the right abstractions in the core,
everything else in libraries
Rich type system
Java meetup @ Thessaloniki - 2017-10-12 4
5. A few highlights
Immutable objects and collections
Type inference
Func ons are rst-class
Everything is an object
Pattern matching
Domain Speci c Languages
REPL
Java meetup @ Thessaloniki - 2017-10-12 5
11. Hello world Scala vs Java
def main(...): Unit = {}
public static void main(...) {}
Unit vs void
No sta c
Return type a er vs before method name & args
Scala object implies Java sta c
Java meetup @ Thessaloniki - 2017-10-12 11
19. Trait (interface)
trait Printer {
def printPDF(pdf: File): Unit
def printRTF(rtf: File): Unit = {
val pdf = ... // convert RTF to PDF
printPDF(pdf)
}
}
Using default methods
(https://github.com/scala/scala/pull/5003)
as of Scala 2.12
Java meetup @ Thessaloniki - 2017-10-12 19
22. Case class
case class Complex(re: Double, im: Double)
val c = new Complex(1.2, 2.0)
val cc = Complex(1.2, 2.0)
No need to use new
Java meetup @ Thessaloniki - 2017-10-12 22
23. Case class
case class Complex(re: Double, im: Double)
val c = new Complex(1.2, 2.0)
val cc = Complex(1.2, 2.0)
// (c == cc) is true
Automatic, derived, structural equality
Compiler implements hashCode and equals
Very handy for immutable domain objects
Java meetup @ Thessaloniki - 2017-10-12 23
24. Case class
case class Complex(re: Double, im: Double)
// instead of
// case class Complex(val re: Double, val im: Double)
Constructor arguments are promoted to class
attributes
Java meetup @ Thessaloniki - 2017-10-12 24
25. Case class
case class Complex(re: Double, im: Double)
val zero = Complex(0, 0)
val one = zero.copy(re = 1)
val i = zero.copy(im = 1)
Builtin copy()
Java meetup @ Thessaloniki - 2017-10-12 25
26. Case class ‐ Pa ern matching
case class Complex(re: Double, im: Double)
val c: Complex = ...
c match {
case Complex(0, 0) => // zero
case Complex(1, 0) => // real unit
case Complex(0, 1) => // imaginary unit
case Complex(a, b) if a == b => // equal coordinates
case Complex(a, b) => // all other cases ...
}
Java meetup @ Thessaloniki - 2017-10-12 26
27. Case class ‐ ASTs
ast.scala
sealed trait AstNode
case class Expr(n: Number) extends AstNode
case class Add(left: Expr, right: Expr) extends AstNode
other.scala
val x: AstNode = parseSourceCode(...)
x match {
case Expr(n) => ...
case Add(left, right) => ...
}
Java meetup @ Thessaloniki - 2017-10-12 27
28. Generics
type parameter in a class
trait Ordered[T] {
def < (that: T): Boolean
def <=(that: T): Boolean
...
}
class ANumber(x: Int) extends Ordered[ANumber] { ... }
Ordered[T] characterizes a type T that has a single,
natural ordering.
Java meetup @ Thessaloniki - 2017-10-12 28
29. Generics
Collections
final class Array[T] // mutable
sealed abstract class List[T] // immutable
val a = Array(1, 2, 3)
val b = List(1, 2, 3)
val c = 1 :: 2 :: 3
Java's Collection<T> becomes Collection[T]
Java meetup @ Thessaloniki - 2017-10-12 29
31. digression: List again
sealed abstract class List[+A] extends AbstractSeq[A]
with LinearSeq[A]
with Product
with GenericTraversableTemplate[A, List]
with LinearSeqOptimized[A, List[A]]
with Serializable
Java meetup @ Thessaloniki - 2017-10-12 31
35. Func on (defini on)
trait Function1[A, B] {
def apply(a: A): B
}
We can also represent the type Function1[A, B] as
A => B or
(A) => B
This is a total function
Java meetup @ Thessaloniki - 2017-10-12 35
36. Func on
Math:
f : A → B
Scala:
f: A => B
f: Function1[A, B]
Java:
Function1<A, B> f
Java meetup @ Thessaloniki - 2017-10-12 36
37. Func on (declara on)
val s_length:
(String) => Int =
(s: String) => s.length
Notice how the method length of class String was
promoted to a function.
Java meetup @ Thessaloniki - 2017-10-12 37
38. Func on (declara on)
val s_length: (String) => Int = s => s.length
// or
val s_length: (String) => Int = _.length
With some nice syntactic sugar
Java meetup @ Thessaloniki - 2017-10-12 38
39. Func on (applica on)
We apply a function f of type A => B
val f: A => B = ...
to a value of type A
val x: A = ...
using intuitive syntax
f(x)
Java meetup @ Thessaloniki - 2017-10-12 39
40. Func on (applica on)
... which gets desugared to
f.apply(x)
Remember that Function1 is de ned with one
method:
trait Function1[A, B] {
def apply(a: A): B
}
Java meetup @ Thessaloniki - 2017-10-12 40
41. Func on (applica on)
... which gets desugared to
f.apply(x)
Everything is an object
Java meetup @ Thessaloniki - 2017-10-12 41
42. Func on (applica on)
apply is a binary method and you can also write
f apply x
Same thing for computing e.g. the maximum of two
integers
x max y vs x.max(y)
Java meetup @ Thessaloniki - 2017-10-12 42
44. map
Map each element of a collection to a new
element, according to a well de ned function
trait Collection[A] {
def map[B](f: A => B): Collection[B]
}
Java meetup @ Thessaloniki - 2017-10-12 44
45. map
Map each element of a collection to a new
element, according to a well de ned function
trait Collection[A] {
def map[B](f: A => B): Collection[B]
}
scala> List("a", "bb").map(x => x.length)
res2: List[Int] = List(1, 2)
Java meetup @ Thessaloniki - 2017-10-12 45
46. map
Map each element of a collection to a new
element, according to a well de ned function
trait Collection[A] {
def map[B](f: A => B): Collection[B]
}
scala> List(1, 2, 3).map( n => isOdd(n) )
res3: List[Boolean] = List(true, false, true)
Java meetup @ Thessaloniki - 2017-10-12 46
47. map
Map each element of a collection to a new
element, according to a well de ned function
trait Collection[A] {
def map[B](f: A => B): Collection[B]
}
alist.map(x => isOdd(x))
alist.map( isOdd(_) )
alist.map( isOdd )
alist map isOdd
Java meetup @ Thessaloniki - 2017-10-12 47
48. ... from map to Map
The generic type is Map[A, B]
The default implementation is immutable
val numbers: Map[Int, String] = Map()
or
val numbers = Map[Int, String]()
Java meetup @ Thessaloniki - 2017-10-12 48
50. ... and then to groupBy
Now that we have Lists and Maps
scalal> val list = List(1, 2, 3)
list: List[Int] = List(1, 2, 3)
scala> val isOdd = (x: Int) => x % 2 == 1
isOdd: Int => Boolean = <function>
scala> val oddeven = list.groupBy(isOdd)
oddeven: scala.collection.immutable.Map[Boolean,List[Int]] =
Map(false -> List(2), true -> List(1, 3))
Java meetup @ Thessaloniki - 2017-10-12 50
56. Op on
trait Option[+T]
case class Some[T](t: T) extends Option[T]
case object None extends Option[Nothing]
Nothing is a subtype of every other type but it has no
instances
Java meetup @ Thessaloniki - 2017-10-12 56
57. Op on
scala> val xOpt: Option[Complex] = Option(null)
xOpt: Option[Complex] = None
scala> val x = xOpt.getOrElse(Complex(0, 0))
x: Complex = Complex(0.0,0.0)
Java meetup @ Thessaloniki - 2017-10-12 57
58. Op on (pa ern match)
xOpt match {
case Some(Complex(re, im)) => ...
case None =>
}
Java meetup @ Thessaloniki - 2017-10-12 58
59. Op on (for comprehension)
for {
x <- xOpt
} { ... }
If we only care about the Some() case.
In effect, you can view Option as a simple
collection of at most one item.
Java meetup @ Thessaloniki - 2017-10-12 59
60. For comprehension
for {
item <- List(1, 2, 3)
} yield item * 2
Computes a new list with each item doubled.
This is a map in disguise.
Java meetup @ Thessaloniki - 2017-10-12 60
61. For comprehension
for {
item <- List(1, 2, 3)
} yield item * 2
same as
List(1, 2, 3).map(_ * 2)
Java meetup @ Thessaloniki - 2017-10-12 61
62. For comprehension
for {
item <- List(1, 2, 3)
} yield item * 2
same as
List(1, 2, 3).map(_ * 2)
Remember that
List(1, 2, 3).map(x => x * 2)
Java meetup @ Thessaloniki - 2017-10-12 62
65. Monads! (in another talk)
for {
x <- Some(Complex(0.0, 1.0))
m <- List(1.0, 2.0, 3.0)
} yield Complex(x.re * m, x.im * m)
Java meetup @ Thessaloniki - 2017-10-12 65
66. Monads! (in another talk)
for {
x <- Some(Complex(0.0, 1.0))
m <- List(1.0, 2.0, 3.0)
} yield Complex(x.re * m, x.im * m)
What about this?
for {
x <- None
m <- List(1.0, 2.0, 3.0)
} yield Complex(x.re * m, x.im * m)
Java meetup @ Thessaloniki - 2017-10-12 66
76. Opinions circa 2009
"If I were to pick a language to use today other
than Java, it would be Scala"
James Gosling, creator of Java
"If someone had shown me the 'Programming in
Scala' book back in 2003, I'd probably have never
created Groovy"
James Strachan, creator of Groovy
Java meetup @ Thessaloniki - 2017-10-12 76