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 Intro training @ Lohika, Odessa, UA.
This is a basic Scala Programming Language overview intended to evangelize the language among any-language programmers.
Scala Intro training @ Lohika, Odessa, UA.
This is a basic Scala Programming Language overview intended to evangelize the language among any-language programmers.
The Scala programming language has been gaining momentum recently as an alternative (and some might say successor) to Java on the JVM. This talk will start with an introduction to basic Scala syntax and concepts, then delve into some of Scala's more interesting and unique features. At the end we'll show a brief example of how Scala is used by the Lift web framework to simplify dynamic web apps.
I used these slides for a Scala workshop that I gave. They are based on these: http://www.scala-lang.org/node/4454. Thanks to Alf Kristian Støyle and Fredrik Vraalsen for sharing!
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.
Practical Functional Programming Presentation by Bogdan Hodorog3Pillar Global
Bogdan Hodorog's presentation on Practical Functional Programming at the Functional Angle Meetup help at 3Pillar's office in Timisoara. Bogdan Hodorog is a Software Engineer who is passionate about building, trying, and playing with software...of all sorts. He currently specializes in Python but is interested in programming languages ad operating systems of all kinds.
How to Avoid Getting Malware on Your ComputerJillian Stone
If you have been a victim of being attacked by malware you'll want to take a look at this PowerPoint. Malware can be avoided by being alert and attentive when you surf the web. Check it out so you can avoid the pitfalls it addresses.
The Five Stages of Accepting Negative Customer Feedback - Jessica Hall's Pres...3Pillar Global
Director of Product Consulting Jessica Hall presented "Five Stages of Accepting Negative Feedback" at Ela Conf on November 4, 2016. Her presentation goes through the five stages of accepting negative customer feedback and how to reframe it to see it as the gift that it is.
The Scala programming language has been gaining momentum recently as an alternative (and some might say successor) to Java on the JVM. This talk will start with an introduction to basic Scala syntax and concepts, then delve into some of Scala's more interesting and unique features. At the end we'll show a brief example of how Scala is used by the Lift web framework to simplify dynamic web apps.
I used these slides for a Scala workshop that I gave. They are based on these: http://www.scala-lang.org/node/4454. Thanks to Alf Kristian Støyle and Fredrik Vraalsen for sharing!
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.
Practical Functional Programming Presentation by Bogdan Hodorog3Pillar Global
Bogdan Hodorog's presentation on Practical Functional Programming at the Functional Angle Meetup help at 3Pillar's office in Timisoara. Bogdan Hodorog is a Software Engineer who is passionate about building, trying, and playing with software...of all sorts. He currently specializes in Python but is interested in programming languages ad operating systems of all kinds.
How to Avoid Getting Malware on Your ComputerJillian Stone
If you have been a victim of being attacked by malware you'll want to take a look at this PowerPoint. Malware can be avoided by being alert and attentive when you surf the web. Check it out so you can avoid the pitfalls it addresses.
The Five Stages of Accepting Negative Customer Feedback - Jessica Hall's Pres...3Pillar Global
Director of Product Consulting Jessica Hall presented "Five Stages of Accepting Negative Feedback" at Ela Conf on November 4, 2016. Her presentation goes through the five stages of accepting negative customer feedback and how to reframe it to see it as the gift that it is.
Companies like PBS have all new challenges in meeting their customer demands with the increasing adoption of disruptive technologies. Simply taking content delivered across traditional channels like the TV and website no longer apply. To build a meaningful experience that leverages the vast amounts of content – PBS and 3Pillar developed a ground-up meta-data architecture that combined the two very disparate worlds of structured and unstructured data. This metadata strategy allows PBS to be predictive in serving up content; it allows PBS to run analytics for improving the experience and optimizing their business strategy.
How to Avoid Getting Malware on your ComputerJillian Stone
If you've been a victim of being attacked by malware you'll want to see this presentation. You can avoid this by being alert and attentive when you surf the web. Check it out so you you can avoid the pitfalls it addresses.
Three Things a New Product Team Needs - Jessica Hall's Presentation at the Bu...3Pillar Global
Director of Product Consulting Jessica Hall presented "Three Things a New Product Team Needs" at the Business of Software Conference on September 13, 2016. Her presentation succinctly described the three necessities for a new product team to be successful.
Learn about Windows / Linus monitoring
How DevOps could play a role in server monitoring space
Understand the advantages of agent-based server monitoring
Use of Plugins to create custom monitoring via DLL, Shell, Vbscript etc.. and use of Nagios plugins.
This presentation was presented at OSS camp in New Delhi. It deals with the basics of Scala language and how we can use it to build scalable Applications
Spring Day | Spring and Scala | Eberhard WolffJAX London
2011-10-31 | 09:45 AM - 10:30 AM
Spring is widely used in the Java world - but does it make any sense to combine it with Scala? This talk gives an answer and shows how and why Spring is useful in the Scala world. All areas of Spring such as Dependency Injection, Aspect-Oriented Programming and the Portable Service Abstraction as well as Spring MVC are covered.
Great Ideas Don't Always Make Great Products - Jonathan Rivers' Presentation ...3Pillar Global
The presentation that accompanied 3Pillar CTO Jonathan Rivers' talk at Health 2.0 in Santa Clara, CA on September 17, 2018. Jonathan covered 3 core tenets of building successful digital products in the healthcare space: making data-driven design choices, placing a relentless focus on the customer, and minimizing time to value.
Alok Jain's presentation from the NoVA UX Meetup on November 14th on the concept of design sprints. Alok covers how companies like Google employ design sprints to launch products to market more quickly and what a typical design sprint looks like. Alok Jain is a designer, innovator, and entrepreneur and the Director of User Experience & Design at 3Pillar Global.
Using Prototypes to Validate Product Strategy - Product Camp DC Presentation ...3Pillar Global
A presentation for Product Camp DC on how to use prototypes to validate market need for a product idea. Jessica Hall, Director of 3Pillar's Innovate Practice, and Kenal Shah, Senior Product Manager, gave the presentation at LivingSocial HQ on October 11, 2014.
Less, But Better - Dieter Rams' Principles of Good Design3Pillar Global
A presentation from 3Pillar Senior UX Designer David Rhyne on Dieter Rams' 10 Principles of Good Design. Among the principles put forward by Rams as most important to design are that it is innovative and makes a product useful and understandable.
Erik Isaksen and Brian Monzingo presented"Let's Get to Work: A Prototyping Case Study" at the NoVA UX Meetup on Wednesday, June 18 at AddThis HQ in Vienna. Erik and Brian shared lessons learned from their experiences on a 6-week HTML prototyping engagement built for a global investment company. In addition to sharing the successes that came out of this engagement, they also looked at failures and lessons learned.
Automated Performance Testing for Desktop Applications by Ciprian Balea3Pillar Global
PowerPoint presentation by 3Pillar's Ciprian Balea, QA Lead, which was delivered at the Romanian Testing Conference (RTC) 2014 in Cluj-Napoca, Romania on May 15, 2014.
Prototyping for Business Outcomes at ModevUX3Pillar Global
A presentation on early-stage prototyping given at ModevUX titled "Prototyping for Business Outcomes." The presentation was given by Jessica Hall, Director of 3Pillar Global's Innovate Practice, and Erik Isaksen, a Senior UX Engineer at 3Pillar Global. In the talk, Jessica and Erik discuss how to identify business outcomes, what prototypes are and are not, how to scope a prototype, and more.
Prototyping Your Way to Better and Faster Outcomes 3Pillar Global
Jessica Hall, Director of 3Pillar Global's Innovate practice, gave a presentation on prototyping to the Intelligence Community Interactive Alliance Conference on February 7, 2014 in Chantilly, VA.
The presentation covers blending agile, lean, and design thinking practices to get deliverables to stakeholders and users more quickly. Prototypes provide a way to show leadership a product vision and speed time to market by surfacing engineering, usability, and content challenges early in the development process.
MoDev East 2012 Presentation on Product Modernization3Pillar Global
3Pillar's Dan Klaussen conducted a panel at MoDev East 2012 that centered on creating software products that meet the needs of mobile consumers. The panel featured executives from Gannett and from 3Pillar clients Carfax, Micropact, and Wedding Wire. This presentation guided the discussion and contains a number of interesting tidbits about the impact a well thought-out software strategy can have on a company's overall business.
Visualizing Relationships: Journalistic Problems in a Digital Age3Pillar Global
A presentation from Marcos Vanetta, Technical Lead and web developer at 3Pillar Global, and Mariano Blejman of Spanish-language newspaper Pagina 12 that was given at the 2012 Mozilla Festival in London, England.
3Pillar Global's Kit Unger and Alok Jain to Explore "How Customers Think" at ...3Pillar Global
Businesses today need to operate in the context of an experience-based economy. To build exceptional experiences, they need to understand who their customers are, what their goals and needs are, and how they align to the business objectives. Unger and Jain’s session provided the attendee with a step-by-step overview in how to build goal-driven design for seamless experiences across multiple channels. Techniques for crafting those experiences has also been discussed.
Enhancing Research Orchestration Capabilities at ORNL.pdfGlobus
Cross-facility research orchestration comes with ever-changing constraints regarding the availability and suitability of various compute and data resources. In short, a flexible data and processing fabric is needed to enable the dynamic redirection of data and compute tasks throughout the lifecycle of an experiment. In this talk, we illustrate how we easily leveraged Globus services to instrument the ACE research testbed at the Oak Ridge Leadership Computing Facility with flexible data and task orchestration capabilities.
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.
Strategies for Successful Data Migration Tools.pptxvarshanayak241
Data migration is a complex but essential task for organizations aiming to modernize their IT infrastructure and leverage new technologies. By understanding common challenges and implementing these strategies, businesses can achieve a successful migration with minimal disruption. Data Migration Tool like Ask On Data play a pivotal role in this journey, offering features that streamline the process, ensure data integrity, and maintain security. With the right approach and tools, organizations can turn the challenge of data migration into an opportunity for growth and innovation.
In software engineering, the right architecture is essential for robust, scalable platforms. Wix has undergone a pivotal shift from event sourcing to a CRUD-based model for its microservices. This talk will chart the course of this pivotal journey.
Event sourcing, which records state changes as immutable events, provided robust auditing and "time travel" debugging for Wix Stores' microservices. Despite its benefits, the complexity it introduced in state management slowed development. Wix responded by adopting a simpler, unified CRUD model. This talk will explore the challenges of event sourcing and the advantages of Wix's new "CRUD on steroids" approach, which streamlines API integration and domain event management while preserving data integrity and system resilience.
Participants will gain valuable insights into Wix's strategies for ensuring atomicity in database updates and event production, as well as caching, materialization, and performance optimization techniques within a distributed system.
Join us to discover how Wix has mastered the art of balancing simplicity and extensibility, and learn how the re-adoption of the modest CRUD has turbocharged their development velocity, resilience, and scalability in a high-growth environment.
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisGlobus
JASMIN is the UK’s high-performance data analysis platform for environmental science, operated by STFC on behalf of the UK Natural Environment Research Council (NERC). In addition to its role in hosting the CEDA Archive (NERC’s long-term repository for climate, atmospheric science & Earth observation data in the UK), JASMIN provides a collaborative platform to a community of around 2,000 scientists in the UK and beyond, providing nearly 400 environmental science projects with working space, compute resources and tools to facilitate their work. High-performance data transfer into and out of JASMIN has always been a key feature, with many scientists bringing model outputs from supercomputers elsewhere in the UK, to analyse against observational or other model data in the CEDA Archive. A growing number of JASMIN users are now realising the benefits of using the Globus service to provide reliable and efficient data movement and other tasks in this and other contexts. Further use cases involve long-distance (intercontinental) transfers to and from JASMIN, and collecting results from a mobile atmospheric radar system, pushing data to JASMIN via a lightweight Globus deployment. We provide details of how Globus fits into our current infrastructure, our experience of the recent migration to GCSv5.4, and of our interest in developing use of the wider ecosystem of Globus services for the benefit of our user community.
Understanding Globus Data Transfers with NetSageGlobus
NetSage is an open privacy-aware network measurement, analysis, and visualization service designed to help end-users visualize and reason about large data transfers. NetSage traditionally has used a combination of passive measurements, including SNMP and flow data, as well as active measurements, mainly perfSONAR, to provide longitudinal network performance data visualization. It has been deployed by dozens of networks world wide, and is supported domestically by the Engagement and Performance Operations Center (EPOC), NSF #2328479. We have recently expanded the NetSage data sources to include logs for Globus data transfers, following the same privacy-preserving approach as for Flow data. Using the logs for the Texas Advanced Computing Center (TACC) as an example, this talk will walk through several different example use cases that NetSage can answer, including: Who is using Globus to share data with my institution, and what kind of performance are they able to achieve? How many transfers has Globus supported for us? Which sites are we sharing the most data with, and how is that changing over time? How is my site using Globus to move data internally, and what kind of performance do we see for those transfers? What percentage of data transfers at my institution used Globus, and how did the overall data transfer performance compare to the Globus users?
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Shahin Sheidaei
Games are powerful teaching tools, fostering hands-on engagement and fun. But they require careful consideration to succeed. Join me to explore factors in running and selecting games, ensuring they serve as effective teaching tools. Learn to maintain focus on learning objectives while playing, and how to measure the ROI of gaming in education. Discover strategies for pitching gaming to leadership. This session offers insights, tips, and examples for coaches, team leads, and enterprise leaders seeking to teach from simple to complex concepts.
Globus Connect Server Deep Dive - GlobusWorld 2024Globus
We explore the Globus Connect Server (GCS) architecture and experiment with advanced configuration options and use cases. This content is targeted at system administrators who are familiar with GCS and currently operate—or are planning to operate—broader deployments at their institution.
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.
Software Engineering, Software Consulting, Tech Lead.
Spring Boot, Spring Cloud, Spring Core, Spring JDBC, Spring Security,
Spring Transaction, Spring MVC,
Log4j, REST/SOAP WEB-SERVICES.
A Comprehensive Look at Generative AI in Retail App Testing.pdfkalichargn70th171
Traditional software testing methods are being challenged in retail, where customer expectations and technological advancements continually shape the landscape. Enter generative AI—a transformative subset of artificial intelligence technologies poised to revolutionize software testing.
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Globus
The Earth System Grid Federation (ESGF) is a global network of data servers that archives and distributes the planet’s largest collection of Earth system model output for thousands of climate and environmental scientists worldwide. Many of these petabyte-scale data archives are located in proximity to large high-performance computing (HPC) or cloud computing resources, but the primary workflow for data users consists of transferring data, and applying computations on a different system. As a part of the ESGF 2.0 US project (funded by the United States Department of Energy Office of Science), we developed pre-defined data workflows, which can be run on-demand, capable of applying many data reduction and data analysis to the large ESGF data archives, transferring only the resultant analysis (ex. visualizations, smaller data files). In this talk, we will showcase a few of these workflows, highlighting how Globus Flows can be used for petabyte-scale climate analysis.
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamtakuyayamamoto1800
In this slide, we show the simulation example and the way to compile this solver.
In this solver, the Helmholtz equation can be solved by helmholtzFoam. Also, the Helmholtz equation with uniformly dispersed bubbles can be simulated by helmholtzBubbleFoam.
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?XfilesPro
Worried about document security while sharing them in Salesforce? Fret no more! Here are the top-notch security standards XfilesPro upholds to ensure strong security for your Salesforce documents while sharing with internal or external people.
To learn more, read the blog: https://www.xfilespro.com/how-does-xfilespro-make-document-sharing-secure-and-seamless-in-salesforce/
Your Digital Assistant.
Making complex approach simple. Straightforward process saves time. No more waiting to connect with people that matter to you. Safety first is not a cliché - Securely protect information in cloud storage to prevent any third party from accessing data.
Would you rather make your visitors feel burdened by making them wait? Or choose VizMan for a stress-free experience? VizMan is an automated visitor management system that works for any industries not limited to factories, societies, government institutes, and warehouses. A new age contactless way of logging information of visitors, employees, packages, and vehicles. VizMan is a digital logbook so it deters unnecessary use of paper or space since there is no requirement of bundles of registers that is left to collect dust in a corner of a room. Visitor’s essential details, helps in scheduling meetings for visitors and employees, and assists in supervising the attendance of the employees. With VizMan, visitors don’t need to wait for hours in long queues. VizMan handles visitors with the value they deserve because we know time is important to you.
Feasible Features
One Subscription, Four Modules – Admin, Employee, Receptionist, and Gatekeeper ensures confidentiality and prevents data from being manipulated
User Friendly – can be easily used on Android, iOS, and Web Interface
Multiple Accessibility – Log in through any device from any place at any time
One app for all industries – a Visitor Management System that works for any organisation.
Stress-free Sign-up
Visitor is registered and checked-in by the Receptionist
Host gets a notification, where they opt to Approve the meeting
Host notifies the Receptionist of the end of the meeting
Visitor is checked-out by the Receptionist
Host enters notes and remarks of the meeting
Customizable Components
Scheduling Meetings – Host can invite visitors for meetings and also approve, reject and reschedule meetings
Single/Bulk invites – Invitations can be sent individually to a visitor or collectively to many visitors
VIP Visitors – Additional security of data for VIP visitors to avoid misuse of information
Courier Management – Keeps a check on deliveries like commodities being delivered in and out of establishments
Alerts & Notifications – Get notified on SMS, email, and application
Parking Management – Manage availability of parking space
Individual log-in – Every user has their own log-in id
Visitor/Meeting Analytics – Evaluate notes and remarks of the meeting stored in the system
Visitor Management System is a secure and user friendly database manager that records, filters, tracks the visitors to your organization.
"Secure Your Premises with VizMan (VMS) – Get It Now"
Why React Native as a Strategic Advantage for Startup Innovation.pdfayushiqss
Do you know that React Native is being increasingly adopted by startups as well as big companies in the mobile app development industry? Big names like Facebook, Instagram, and Pinterest have already integrated this robust open-source framework.
In fact, according to a report by Statista, the number of React Native developers has been steadily increasing over the years, reaching an estimated 1.9 million by the end of 2024. This means that the demand for this framework in the job market has been growing making it a valuable skill.
But what makes React Native so popular for mobile application development? It offers excellent cross-platform capabilities among other benefits. This way, with React Native, developers can write code once and run it on both iOS and Android devices thus saving time and resources leading to shorter development cycles hence faster time-to-market for your app.
Let’s take the example of a startup, which wanted to release their app on both iOS and Android at once. Through the use of React Native they managed to create an app and bring it into the market within a very short period. This helped them gain an advantage over their competitors because they had access to a large user base who were able to generate revenue quickly for them.
Developing Distributed High-performance Computing Capabilities of an Open Sci...Globus
COVID-19 had an unprecedented impact on scientific collaboration. The pandemic and its broad response from the scientific community has forged new relationships among public health practitioners, mathematical modelers, and scientific computing specialists, while revealing critical gaps in exploiting advanced computing systems to support urgent decision making. Informed by our team’s work in applying high-performance computing in support of public health decision makers during the COVID-19 pandemic, we present how Globus technologies are enabling the development of an open science platform for robust epidemic analysis, with the goal of collaborative, secure, distributed, on-demand, and fast time-to-solution analyses to support public health.
2. What is Scala?
•A programming language running on the JVM
(also a JS backend)
•Statically typed, combines object-orientation
and functional programming
•Concise
•Fully interoperable with Java
•As fast as Java
2
4. Scala drives its social graph service:
380-400 M transactions/day
Migrated core messaging service
from Ruby to sustain 1000x growth
Approved for general production
use
Location-based social network. All
written in Scala (>5M users).
5
5. Philosophy
• “Growable language” (Guy Steele)
• embed DSLs/add new types
• Scalable language
• same concepts in small and large applications
• Deep rather than broad
• focus on abstraction and composition
6
6. public class Person {
public final String name;
public final int age;
Person(String name, int age) {
this.name = name;
this.age = age;
}
}
class Person(val name: String,
val age: Int)
Java
Scala
7
7. import java.util.ArrayList;
...
Person[] people;
Person[] minors;
Person[] adults;
{ ArrayList<Person> minorsList = new ArrayList<Person>();
ArrayList<Person> adultsList = new ArrayList<Person>();
for (int i = 0; i < people.length; i++)
(people[i].age < 18 ? minorsList : adultsList)
.add(people[i]);
minors = minorsList.toArray(people);
adults = adultsList.toArray(people);
}
val people: Array[Person]
val (minors, adults) = people partition (_.age < 18)
A tuple in a pattern match
Infix method call
Anonymous function
8
8. Overview
•Scala as an Object-Oriented Language
•Scala as a Functional Programming
Language
•Scala as a host language for DSLs
9
11. The bottom line
•Every value is an object
•Everything is an expression (evaluates to
a value)
•Every operation is a method call
•What about primitives?
12
12. type can be inferred
val x: Int = 10
val y = x + 10
same as x.+(10)
13
13. final class Int {
def +(y: Int): Int = <native>
def -(y: Int): Int = <native>
def *(y: Int): Int = <native>
def /(y: Int): Int = <native>
...
}
The compiler treats all primitives as if they were instances of
such classes (but uses primitive values for performance)
14
15. scala> val c = new Complex(1, 2)
c: test.Complex = 1 + 2i
scala> val c1 = new Complex(2, 2)
c1: test.Complex = 2 + 2i
scala> c + c1
res0: test.Complex = 3 + 4i
16
16. Everything is an
expression
•No statements
•Reduces the need for return and side-effects
17
17. def max(x: Int, y: Int) =
if (x > y) x else y
no return statement
scala> val t = {
| x = x + 10
| x - 1
| }
t: Int = 9
return type inferred to Int
blocks evaluate to last
expression
18
18. What about println?
scala> val x = println("hello, world")
hello, world
x: Unit = ()
The Unit type is like void in Java: no interesting value
19
20. Classes
•Similar to Java classes
•have fields, methods, parameters and
types
•every member can be overridden
•except classes (no virtual classes)
•any member can be abstract
21
21. explicit abstract class parameters/fields
abstract class Node[T](val v: T, next: Node[T])
extends List(v, next) {
val cache: Int
def first: T
def children = List(next)
override def toString = "Node " + v
}
22
super ctor call
When compiled, this class will look and behave exactly like the
obvious translation to a Java class. No glue code necessary.
22. Traits
•Like Java interfaces, but in addition
•allow concrete methods, fields, types
•Like Scala classes, but without
constructor parameters
•Allow (a form of) multiple inheritance
•mix-in composition
23
23. type parameter can extend Java classes
trait Ordered[A] extends java.lang.Comparable[A] {
def compare(that: A): Int
def < (that: A): Boolean = (this compare that) < 0
def > (that: A): Boolean = (this compare that) > 0
def <= (that: A): Boolean = (this compare that) <= 0
def >= (that: A): Boolean = (this compare that) >= 0
}
classes mixing in Ordered will get all these methods ‘for free’
class Complex extends Ordered[Complex] {
def compare(that: Complex): Int = ...
}
24
24. if (c1 > c2) c1 else c2
val xs: List[Complex]
xs.sorted
25
26. Mix-in example: Cells
•model mutable cells that contain a single
value of some arbitrary type.
•Additionally, define logging and
undoable variants.
27
27. A class for generic cells
class Cell[T](val init: T) {
private var v = init
def get(): T = v
def set(v1: T): Unit = { v = v1 }
override def toString: String =
"Cell("+ v +")"
}
make init available as a field
mutable field
28
28. A trait for undoable cells
trait UndoableCell[T] extends Cell[T] {
import mutable.ArrayStack
private var hist = new ArrayStack[T]()
override def set(v1: T): Unit = {
hist.push(super.get())
super.set(v1)
}
def undo(): Unit =
super.set(hist pop)
}
29
29. A trait for logging cells
trait LoggingCell[T] extends Cell[T] {
override def get(): T = {
println("getting "+ this)
super.get()
}
override def set(v1: T): Unit = {
println("setting "+ this +" to "+ v1)
super.set(v1)
}
}
30
30. Mix-in composition
new Cell(0)
new Cell(0)
with LoggingCell[Int]
new Cell(0)
with LoggingCell[Int]
with UndoableCell[Int]
new Cell(0)
with UndoableCell[Int]
with LoggingCell[Int]
cell with logging
cell with logging
and undoing
cell with undoing
and logging
31
31. Mix-in composition
•traits can be stacked
•the call to super is dynamically bound
•super calls the ‘preceding’
implementation in the instantiated object
32
33. Modules
•Scala uses objects and traits for module
composition
•Composition through mixins
•Modules may require another module
34
34. Customers and DB
•Module Accounting
•requires a logger, a customer service
•Module Customers
•requires a logger, provides the
customer service
35
35. trait Accounting { this: Customers =>
val logger: Logger
customers.getCustomers // ..
}
trait Customers {
val logger: Logger
val customers: CustomerService
class CustomerService {
requires module Customers
def getCustomers: Unit = ()
//...
}
}
36
36. object App extends Accounting
with Customers {
val logger = // logback
val customers = new CustomerService
}
The application uses (some) concrete implementations of Accounting
and CustomerService.
37
37. This gives dependency
injection in the language!
object TestApp extends Accounting
with Customers {
val logger = // println based
val customers = new MockCustomerService
}
The test environment uses a mock CustomerService.
38
38. Summary
•Basic O-O features
•classes and traits
•type inference
•mix-in composition
•Advanced type system
•modules and dependencies
•dynamic binding of super
39
40. What is FP?
•Use of functions (in the mathematical sense)
•referential transparency (no side-effects)
•Immutable objects
•Functions are values
41
41. Scala as FPL
•function literals and closures
•use val instead of var
•immutable collections in the standard
library
•opt-in lazy evaluation
•curry-ing (definition site)
42
42. Function literals
scala> val succ = (x: Int) => x + 1
succ: (Int) => Int = <function1>
scala> succ(1)
res3: Int = 2
43
43. Equivalent forms
•x => x + 1 (infer type)
•1 + (partial application)
•_ + 1 (placeholder notation)
•compare _ (eta expansion)
44
45. val xs = List(1, 2, 3, 4, 5)
xs.foreach(println)
scala> xs.forall(_ < 10)
res5: Boolean = true
scala> xs.map(_ * 2)
res6: List[Int] = List(2, 4, 6, 8, 10)
def findBelow(limit: Int) =
persons.filter(_.age < limit)
lexical scoping: functions may refer and
even modify anything in scope
46
46. Everything is an object
•Closures are objects as well
•(compiler generated) instances of trait
Function1[A, B]
trait Function1[R, A] {
def apply(x: A): R
}
47
47. (More) sugar
•..but why can I call succ(10)?
•f(args) is desugared to f.apply(args)
•you can define your own ‘apply’
methods
•..can I subclass FunctionN?
48
48. Library
•Yes! Lots of collections are functions
•Sequences are Int => T
•Sets are T => Boolean
•Maps are K => V
49
53. For-comprehensions
may have any number of generators
p is in scope for other generators
for (p <- persons; pr <- p.projects;
if pr.overdue) yield p.name
guard construct a new collection of the same
type, element by element
res10: List[String] = List(“John”, “Harry”)
54
54. For-comprehensions
•Desugared to calls to filter, map, flatMap
•..any class implementing those methods
•Could be used to query a database
•implement filter, map, flatmap to
generate and forward SQL
•Slick, ScalaQuery, Squeryl
55
56. Pattern matching
•A way to deconstruct structured data
•A powerful switch statement (expression,
really)
57
57. Pattern matching
abstract class Expr
case class Literal(n: Int) extends Expr
case class Add(left: Expr, right: Expr)
extends Expr
case class Mul(left: Expr, right: Expr)
extends Expr the case modifier enables these classes
to participate in pattern matching
58
58. Pattern matching
def opt(e: Expr) = e match {
case Add(l, Literal(0)) => l
case Mul(l, Literal(1)) => l
case _ => e
}
patterns can be nested
literals match only their value
default case
59
59. Patterns everywhere
•Great way to process XML, JSON, etc.
•exception handlers are also patterns!
•..and also declarations
60
60. try {
//...
} catch {
case EvalError(line, msg) => //..
case e: IndexOutOfBoundsException => //..
}
61
62. Implicit conversions
•We can “grow” the language with
Complex numbers
•c + 1 works, but what about 1 + c?
63
63. Implicit conversions
•Allow user-defined conversions
•When the type does not have a member
•Find a method marked implicit that
takes the original type to one that has it
•Call the method implicitly
•It’s an error to have more than one
applicable conversions
64
64. implicit def intIsComplex(n: Int) =
new RichInt(n)
class RichInt(n: Int) {
def + (other: Complex) =
new Complex(n) + other
}
1 + c intIsComplex(1).+(c)
65
65. implicit class RichInt(n: Int) {
def + (other: Complex) =
new Complex(n) + other
}
Also a great way to adapt existing libraries
66
66. implicit class RichArray[T](as: Array[T]) {
def foreach(f: T => Unit) = ???
def map[U](f: T => U) = ???
def filter(f: T => Boolean) = ???
// ...
}
Scala arrays are Java arrays, but can still have the same API
67
67. Actor-based concurrency
•Threads and locks are error-prone
•(in fact, mutable shared data)
•Alternative: Message-passing with actors
•(no sharing)
•Implemented entirely in the library
•(3 other implementations out there)
68
68. Actors in Scala
actor ! msg
asynchronous message send
method call
receive {
case Ping(a1) => a1 ! msg
case Pong(_) => ..
}
Normal pattern match translated
to PartialFunction
69