亳从仂仍舒亶 舒仍舒仄舒从 "Functional Programming basics for PHP developers"Fwdays
油
Functional Programming becomes very popular nowadays. What is it? Is it a hype or panacea? Should you deal with it as a PHP programmer? Let's find out!
Scala has a static, strong, and Turing complete type system that can infer types. It supports object-oriented programming with named types like Dog and functional programming with parameterized types like List[Int]. New types can be defined through classes, traits, case classes, and type members. Types are more general than classes and include structural types. Variance controls subtype relationships for parameterized types. Type bounds and existential types provide additional type safety. Higher kinded types allow types to be parameterized over other types.
Scala has a static, strong, and Turing complete type system that can infer types. It supports object-oriented programming with named types like Dog and functional programming with parameterized types like List[Int]. New types can be defined through classes, traits, case classes, and type members. Types are more general than classes and include structural types. Variance controls subtype relationships for parameterized types. Type bounds and existential types provide additional type safety. Higher kinded types allow types to be parameterized over other types.
Spark is well-suited for interactive data analysis and machine learning workloads. It can be developed locally in an IDE or the Spark shell before deploying to EMR. When deploying, be sure to install Ganglia for cluster monitoring and debug Spark jobs by running parts of the code in the local Spark shell. Packaging code into a fat JAR, configuring properties like parallelism, and submitting jobs to YARN are required to run Spark programs on EMR at scale.
The Kotlin Programming Language, Svetlana IsakovaVasil Remeniuk
油
The document discusses the Kotlin programming language. It describes Kotlin as a modern, statically typed, object-oriented language that compiles to JVM bytecode or JavaScript. Kotlin was developed by JetBrains as an open source language intended for industrial use. The document then covers various features of Kotlin like its handling of null safety using nullable types, extension functions, smart casts for pattern matching, and approach to collection transformations.
Cake pattern. Presentation by Alex Famin at scalaby#14Vasil Remeniuk
油
The Cake pattern is a dependency injection pattern for Scala that uses traits to define components and their dependencies. It allows defining components and their implementations separately. An object extends the necessary component traits to resolve dependencies and provides the application object graph. The graph is constructed at compile time, ensuring type safety. However, the pattern results in boilerplate code and does not provide strong lifecycle management for the components.
This document provides an overview of different types of software tests including unit tests, integration tests, functional tests, and acceptance tests. It also discusses test-driven development (TDD) and behavior-driven development (BDD). Some key points:
- Unit tests check specific functionality in isolation and use mocking. Integration tests check component integration using real dependencies. Functional tests use real data to test functionality. Acceptance tests are final tests performed by clients.
- TDD involves writing tests first as an interface/trait before implementation. BDD is similar but focuses on defining behavior.
- ScalaTest is a common Scala testing framework that supports different styles like FunSuite, WordSpec. It allows mocking,
The document discusses Scala reflection, which provides a unified API to access information about a program at both compile-time and runtime. This API allows programs to inspect their structure, types, and symbols using trees, mirrors, and universes. It facilitates tasks like runtime compilation, reifying types, and writing macros. The current implementation is available in Scala 2.10 M3, with runtime reflection improved for the upcoming M4 release.
Olexandra Dmytrenko
QA Automating at EPAM Systems
I'll show you how to switch from writing standard code using good old Java7 into writing it using functional way presented in Java8. The training is counted on beginners in the subject who like discovering the new horizons or for those who want to become more firm in using the new lambda features.
This document summarizes Scala concepts covered in previous sessions including object-oriented programming, functional programming, self types, type members, implicits, type classes, logic programming with types, and the Shapeless library. It provides examples and explanations of these concepts.
This document provides a quick guide to Scalding, a Scala wrapper for the Cascading framework that allows for MapReduce-style programming in Scala. Scalding represents data as in-memory collections and allows processing without scripting or user-defined functions. It provides an abstraction over Hadoop MapReduce through concepts like taps, pipes, and sinks. The document demonstrates a word count example in Scalding and provides instructions for building, testing, and deploying Scalding jobs on EMR as well as developing with both field-based and typed APIs. It also shares the author's experiences using Scalding.
This document discusses Wordcount examples in MapReduce, Cascading, and Scalding. Scalding is a Scala wrapper for Cascading that allows working with data like in-memory collections. It includes parsers for CSV and date formats, as well as helper algorithms. The document also provides instructions for building Scalding jobs, deploying them on EMR, and some tips for development including increasing memory limits and reading data directly from HDFS. Resources with more documentation and examples are also listed.
The document discusses Apache Spark, an open-source cluster computing framework. It describes Spark's core components like Spark SQL, MLlib, and GraphX. It provides examples of using Spark from Python and Scala for word count tasks and joining datasets. It also demonstrates running Spark interactively on a Spark REPL and deploying Spark on Amazon EMR. Key points are that Spark can handle batch, interactive, and real-time processing and integrates with Python, Scala, and Java while programming at a higher level of abstraction than MapReduce.
Scala Style by Adform Research (Saulius Valatka)Vasil Remeniuk
油
This document summarizes feedback from a code review session, organized into the following sections: project structure, tests, naming conventions, public APIs, the CumulativePrefixTree data structure, readability, types, catching throwables in Vertica UDFs, and potential topics for future Scala sessions. The reviewer provides suggestions on improving test names, naming conventions, using case classes, reducing tuples, catching failures instead of throwables, and emphasizing types over utils to improve code quality, readability and idiomatic Scala.
Spark is well-suited for interactive data analysis and machine learning workloads. It can be developed locally in an IDE or the Spark shell before deploying to EMR. When deploying, build a fat JAR, upload it to S3, and run a bootstrap script to install and configure Spark on the cluster before submitting jobs with Spark's APIs. The Spark UI and Ganglia monitoring are useful for debugging jobs running on EMR.
This document discusses different build systems like Ant, Maven, Ivy, and sbt that can be used to build Scala and Java projects. It provides an overview of sbt, describing its project layout, usage, and some theory behind how sbt builds projects. Sbt is presented as a powerful build tool that can compile both Java and Scala projects, uses Ivy for dependency management, and has build definitions that are Scala programs. The document also touches on library dependencies, plugins, and resolving dependencies from repositories for sbt projects.
The iteration goals are to refactor code to master Scala concepts like options, Try/Either/Validation, collections, and patterns. It also aims to add persistence using MongoDB and create REST endpoints using Spray HTTP. The document provides links to resources explaining these concepts in Scala and recommends tools like Casbah for MongoDB, Scalatest and ScalaCheck for testing, and Play JSON for serialization.
This document provides an overview of different types of software tests including unit tests, integration tests, functional tests, and acceptance tests. It also discusses test-driven development (TDD) and behavior-driven development (BDD). Some key points:
- Unit tests check specific functionality in isolation and use mocking. Integration tests check component integration using real dependencies. Functional tests use real data to test functionality. Acceptance tests are final tests performed by clients.
- TDD involves writing tests first as an interface/trait before implementation. BDD is similar but focuses on defining behavior.
- ScalaTest is a common Scala testing framework that supports different styles like FunSuite, WordSpec. It allows mocking,
This document provides an overview of the Globus project, which aims to develop a service that digitizes POD (Product, Organization, and Delivery) frameworks. It outlines topics to be covered such as development environment, server-side development, and testing. It describes setting up the development environment in IntelliJet IDEA and SBT. It also details next steps such as creating a project structure in SBT, using appropriate Scala constructs to build the model, integrating with Travis CI for continuous integration, defining the business logic layer in collaboration with teammates, and writing the business logic in Scala.
This document summarizes a system using Cassandra, Spark, and ELK (Elasticsearch, Logstash, Kibana) for processing streaming data. It describes how the Spark Cassandra Connector is used to represent Cassandra tables as Spark RDDs and write RDDs back to Cassandra. It also explains how data is extracted from Cassandra into RDDs based on token ranges, transformed using Spark, and indexed into Elasticsearch for visualization and analysis in Kibana. Recommendations are provided for improving performance of the Cassandra to Spark data extraction.
Funtional Reactive Programming with Examples in Scala + GWTVasil Remeniuk
油
This document provides an overview of functional reactive programming (FRP) with examples using Scala and GWT (Google Web Toolkit). It discusses how FRP can be used to build user interfaces that synchronize state changes automatically in response to events. Key concepts explained include EventStreams, Signals, and how they can be transformed and combined. Examples show how FRP can be used to track mouse position, build stock tickers that update dynamically, and manage collections of values that change over time. The document argues that FRP provides advantages over the traditional observer pattern for building interactive user interfaces.
This document discusses the benefits of using Scala with Vaadin, including a simple programming model without JavaScript, security from all server-side code, beautiful widgets and themes, and performance advantages over other frameworks like PrimeFaces. Scala allows for a more declarative programming style, inline component constructors, delayed initialization, callbacks and higher-order functions to reduce coupling, localization with symbols, navigating nested objects, and eliminating dependencies with structural types. Hot reloading of classes is also possible with JRebel for Scala applications.
This document discusses using Scala and functional programming concepts like the cake pattern and validation in Goozy, a social networking application. It describes how Goozy's API uses Scala for its performance, conciseness and advanced object-oriented features. It also discusses issues with using Lift and how the cake pattern improved organization by encapsulating dependencies. Validation is implemented using Scalaz to catch errors and exceptions are converted to a common error type for reporting. In summary, functional programming brought organization and error handling benefits but also increased complexity compared to exceptions.
3. For comprehensions
Syntactic sugar
For
Scala for 磦仍磳 亳仆舒从亳亠从亳仄 舒舒仂仄, 亠仄 仆亠
comprehensions
By-name
仄亠仆亠亠 仗舒于亳仍舒 仗亠仂弍舒亰仂于舒仆亳 亟仂于仂仍仆仂 仍仂亢仆
parameters
Non local return 亟亳仆 亞亠仆亠舒仂 yield 仂亢亠, 仂 于亰仂于 仄亠仂亟舒 map
Local functions
Lazy values 亟亳仆 亞亠仆亠舒仂 弍亠亰 yield 仂亢亠, 仂 foreach
Generated 亠从仂仍从仂 亞亠仆亠舒仂仂于 舒仆仍亳ム 于仂 flatMap
ByteCode
Binary
compatibility
Questions? f o r ( i < 1 t o 5) (1 to 5) . map { i = i > i }
yield i i (1 to 5) . f o r e a c h {
f o r ( i < 1 t o
println ( i )
5) 油 }
i = println ( i )
>
f o r { i < 1 t o 5 (1 to 5) . f l a t M a p {
j < 1 t o 5} i = (1 to 5) . map { j = i + j }
> >
yield i + j }
仂亟仂弍仆亠亠 仄仂亢仆仂 仗仂亳舒 于 仗亠亳亳从舒亳亳.
3 / 19
4. By-name parameters
Syntactic sugar
For
仂亰仄仂亢仆仂 于 于亰仂于 仄亠仂亟舒 仗亠亠亟舒于舒 于舒亢亠仆亳
comprehensions
By-name
仍亠仆亳于仂 仂 亟亞仂亶 仗亳仄亠 仂亞仂, 亞亟亠 仆亠磦仆仂 仄仂亞 弍
parameters
Non local return
亰舒亳 closures. 弌仍亠亟ム亳亠 亟于舒 仗亳仄亠舒 亳亟亠仆亳仆:
Local functions
Lazy values
d e f foo ( x : => Int ) { d e f foo ( x : ( ) => Int ) {
Generated
ByteCode println ( x ) println ( x ( ) )
} }
Binary
compatibility
foo ( 1 ) foo ( ( ) => 1 )
Questions?
丼仂 亳亰亠亟从舒 仄仂亢亠 仗亳于仂亟亳 从 仂亳弍从亠 (仗舒舒仄亠 弍亟亠
于亳仍 从舒亢亟亶 舒亰, 从仂亞亟舒 从 仆亠仄 弍亟亠
仗仂亳亰于仂亟亳 仂弍舒亠仆亳亠).
4 / 19
6. Local functions
Syntactic sugar
For
Java 仍ミ頴笑 于仗仂仄仂亞舒亠仍仆亶 从仂亟 仂仂仄仍磳 于 于亳亟亠
comprehensions
By-name
private 仄亠仂亟仂于 仆舒 仂于仆亠 从仍舒舒. Scala 仂 仄仂亢仆仂
parameters
Non local return
亟亠仍舒 弍仂仍亠亠 从亳仂于舒仆仆仄, 亠仍亳 亳仗仂仍亰仂于舒
Local functions 仍仂从舒仍仆亠 仄亠仂亟, 仂 仆舒 仂于仆亠 bytecode 仗仂仍舒亠
Lazy values
Generated
仗亳仄亠仆仂 仂亢亠 舒仄仂亠:
ByteCode
Binary
compatibility import scala . runtime . IntRef ;
public class LocalFunctions {
Questions? class LocalFunctions {
p u b l i c void foo () {
def foo {
I n t R e f i $ 1 = new I n t R e f ( 1 ) ;
var i = 1
i n t j$1 = 2;
val j = 2
l o c a l $ 1 ( i$1 , j$1 ) ;
def local {
i += j
油 l o c a l $ 1 ( i$1 , j$1 ) ;
}
}
p r i v a t e f i n a l void local$1 (
local
IntRef intref , i n t i ) {
local
i n t r e f . e l e m += i ;
}
}
}
p u b l i c L o c a l F u n c t i o n s ( ) {}
}
6 / 19
7. Lazy values
Syntactic sugar
For
亅仂 仂亢亠 亳仆舒从亳亠从亳亶 舒舒, 从仂仂亶 仆舒亟仂
comprehensions
By-name
亳仗仂仍亰仂于舒 舒从从舒仆仂 (舒从 从舒从 于仂亰仄仂亢仆 deadlock 亳
parameters
Non local return
仗仂弍仍亠仄 仗仂亳亰于仂亟亳亠仍仆仂亳). 亠亰舒于亳亳仄仂 仂
Local functions 舒仗仂仍仂亢亠仆亳 lazy val, 从仂仄仗亳仍亳亠 仂仆 舒从亳仄 仂弍舒亰仂仄
Lazy values
Generated
ByteCode
import scala . runtime . BoxedUnit ;
Binary p u b l i c c l a s s Lazy {
compatibility public int x () {
i f ( ( b i t m a p $ 0 & 2 ) == 0 )
Questions? synchronized ( this ) {
i f ( ( b i t m a p $ 0 & 2 ) == 0 ) {
x = 1;
bitmap$0 = bitmap$0 | 2;
c l a s s Lazy {
lazy val x = 1
油 }
BoxedUnit _tmp =
}
BoxedUnit . UNIT ;
}
return x ;
}
p u b l i c L a z y ( ) {}
private int x ;
public v o l a t i l e i n t bitmap$0 ;
}
7 / 19
11. Traits
Syntactic sugar
仍亳 trait 仂仍亳舒亠 仂 仂弍仆仂亞仂 亳仆亠亠亶舒 于 Java
Generated
ByteCode 仆舒仍亳亳亠仄 从仂仆从亠仆 仄亠仂亟仂于, 仂 从 仂仂于亠于ム亠仄
Classes and names
Objects 亳仆亠亠亶 弍亟亠 仂亰亟舒仆 从仍舒 Trait$class
Traits
Trait subclasses
亳仄仗仍亠仄亠仆舒亳亠亶 亳 仄亠仂亟仂于.
Linearization
Initialisation order
Binary public abstract class A$class {
compatibility public static int foo ( A $this ,
int x) {
Questions? return 2;
trait A {
}
val x = 1 油 public s t a t i c void $init$ (
A $this
def foo ( x : Int ) = 2
) {
}
$this .
test$A$_setter_$x_$eq (1) ;
}
}
11 / 19
12. Trait subclasses
Syntactic sugar
仍亳 于 Java 仗仂仗舒 亠舒仍亳亰仂于舒 Trait, 于 从仂仂仂仄 亠
Generated
ByteCode 亢亠 亳仄仗仍亠仄亠仆亳仂于舒仆亠 仄亠仂亟, 仂 亳 于亠 舒于仆仂
Classes and names
Objects 仗亳仍仂 弍 亠舒仍亳亰仂于于舒. 亞仂亶 于仂仗仂, 仂 仂
Traits
Trait subclasses
仄仂亢仆仂 亟亠仍舒 仗亠亟亠仍仆仂 仍亠亞从仂:
Linearization
Initialisation order
Binary i n t foo ( ) { r e t u r n Trait$class . foo ( t h i s ) ; }
compatibility
Questions?
仍舒亠 仆舒仍亠亟仆亳从仂于 仆舒仗亳舒仆仆 仆舒 Scala, 仂 亢亠 舒仄仂亠
亟亠仍舒亠 从仂仄仗亳仍仂.
12 / 19
13. Linearization
Syntactic sugar
亅仂 舒仍亞仂亳仄 亠弍亠 从仂仄仗亳仍仂, 仂弍 仂仗亠亟亠仍亳,
Generated
ByteCode 于 从舒从仂仄 仗仂磲从亠 仆舒亟仂 亳从舒 仄亠仂亟 于 弍舒亰仂于 从仍舒舒.
Classes and names
Objects
Traits
Trait subclasses trait A extends B
Linearization trait B
Initialisation order class C extends B
Binary class D extends C with A
compatibility
Questions?
亟亠 仗仂磲仂从 D, A, C, B.
仍亳 亟于舒 仄亠仂亟舒 仂亟亳仆舒从仂于仂亶 亳亞仆舒仂亶 弍亠亰
仄仂亟亳亳从舒仂舒 override 仗亳仂亟 于 从仍舒 仆舒仍亠亟仆亳从 亳亰
仗亠亠亶仂于, 仂 仂亳弍从亳 仆亠 弍亟亠, 舒从 从舒从 仂弍磶舒亠仍仆仂
仆舒亟仂 弍亟亠 仗亠亠仂仗亠亟亠仍亳 亳亞仆舒. 仍亳 亢亠
从仂亞仂-仂 亠 仄仂亟亳亳从舒仂 override, 仄仂亢亠 仍亳
仆亠磦仆亶 override 仂亞仍舒仆仂 仗舒于亳仍舒仄 仍亳仆亠舒亳亰舒亳亳.
13 / 19