Course 'Intermediate Scala'
$100usd

The "Using Partially Applied Functions" lecture is not free and you are not enrolled in the course, or you are not logged in. Information about the lecture follows. Click on the About the Course and Course Outline tabs above to learn more about the course. You can enroll by clicking on the button on the upper right of this page.

Lecture Contents

The Loan Pattern

Using the Loan Pattern

Eta Expansion Type Hints

Generating a Partially Applied Function from a Parametric Method

Eta Expansion Example

Placeholder Syntax Example

Nesting Partially Applied Functions

Expanded Review

Review Example 1

Review Example 2

Review Example 3

Exercise – Wrapping Database Operations With the Loan Pattern

Solution

References: Lecture Immutable Collections
Lecture Parametric Types
Lecture Partially Applied Functions
Lecture Functions are First Class
Lecture More Fun With Functions
Referenced by: Lecture Scala I/O
Lecture Partially Applied Functions

Abstract

Common usage patterns of partially applied functions are introduced, including the Loan Pattern, various ways of using type hints, nested partially applied functions and generating partially applied functions from parametric methods. An extended review of partially applied functions will stretch your brain. The exercise walks you through using partially applied functions to make writing database code easy.

Revision History

Date Changes
2015-09-17 Numerous changes to transcript and republished video
2014-09-18 Fixed compile error in courseNotes/src/main/scala/solutions/DBOps.scala
2014-09-12 Improved the Wrapping Database Operations With the Loan Pattern Exercise
2014-08-11 Published video
2014-08-09 Hived from Partially Applied Functions lecture. Published transcript.
You will feel right at home learning Apache Spark, or Akka after taking this course

This Intermediate Scala course builds on the Introduction to Scala course. Many concepts and techniques are introduced, with lots of working code examples and exercises, including functional programming, implicits, process control, I/O, collections, pattern matching, combinators, partial functions, application configuration techniques, memoization, and multithreading (including parallel collections, Futures, Promises and Akka Actors). You can see a detailed outline from the Outline tab of this web page. We guarantee that taking this course will make you work hard; and as a result students gain a lot of practical, hands-on experience with Scala. The concepts taught allow you to feel comfortable with the code that you will find in Apache Spark and Play Framework 2 for Scala projects, and motivational Spark and Play examples are provided in the course.

As with the Introduction to Scala course, this course is based on code samples that can be pasted into the Scala REPL, and that code is also provided in the the courseNotes directory. The course consists of 9 hours of video, over 450 pages of lecture notes (if printed as an O'Reilly-sized book), more than six-dozen sample programs and about a dozen exercises.

We suggest that students take this course before moving on to Introduction to Play Framework for Scala, Apache Spark or working on other industrial-strength Scala projects.

In addition to self-paced online learning, Micronautics Research (the company that operates ScalaCourses.com) offers on-site and remote delivery for this course. Our instructors use videoconferencing to provide office hours so students can interact directly. Please contact us for further details.

The overview video on the front page of this web site discusses how ScalaCourses.com works.

Prerequisites

Introduction to Scala or equivalent.

 

Date Lecture Changes
2020-02-11 Collection Extras Updated scala-collection-compat version to 2.1.4
2019-10-09 Implicit Values Added sections Git Clone the Course Notes and Refer to Lecture Transcripts and republished video.
2019-09-08 Scala I/O Updated transcript code to match git repo
2019-08-15 Collection Extras Updated version of scala-collection-compat library in transcript.
2019-07-29 Hash Tables Published video
2019-07-27 Collections Overview Mentioned Google Guava weak hash map.
2019-07-26 Collections Overview Enhanced the Benchmark and Performance section with the conclusions from the now out-of-date collections benchmark for Scala 2.8 - 2.12.
2019-07-24 Collections Overview Added new section scala-collection-contrib to the transcript.
2019-07-24 Hash Tables Rewrote transcript
2019-07-23 Introduction to Actors Updated the code in the git repo for this lecture for Scala 2.13 and Akka 2.5.23, however the Testing Actors sections of the transcript and video have not yet been updated to match the code.
2019-07-23 Implicit Classes Updated Symbol usage and explanation for Scala 2.13. Also updated sample code in git repo.
2019-07-22 Collections Overview Reordered the material. Republished video, updated for Scala 2.13. Updated code examples in git repository.
2019-07-22 Hash Tables Hived hashtable material from Collections Overview into this new  lecture. Moved code examples for this lecture in the git repository into HashFun.scala.
2019-07-21 Collections Overview and Arrays and Array-Adjacent Types Moved the Array section into the new Arrays and Array-Adjacent Types lecture and made the new lecture visible. Moved code examples in git repository to ArrayFun.scala. Published the video of the sections that had passed technical review, marked the other sections "awaiting tech review".
2019-07-20 scala.jdk Converter Libraries Part 1 and
scala.jdk Converter Libraries Part 2
Moved this lecture so it is grouped with the other lectures on converters. Rewrote the exercise and updated the git repo with the solution. Did an exhaustive technical review of the material. Split into two lectures
2019-07-20 Collection Extras Hived from scala.jdk Converter Libraries lecture and published video.
2019-07-18 To Converters Hived from scala.jdk Converter Libraries lecture and published video.
2019-07-18 scala.jdk Converter Libraries Edited for better flow while recording the video. Expanded the FunctionConverters section with practical examples of Scala/Java interop. Added caveats about the limitations of our support; this is a Scala course, so we don't explain or support Java. Similarly, Scala/Java interop (especially functions and futures) is a huge topic that we used to provide an entire course on back in the days of Java 6 &7 with Scala 9 and 10. Scala 3, due later in 2019, will change the interop API yet again, rendering this lecture out of date. If there is sufficient interest, we'll undertake a research project to produce a new course on the topic. We won't answer questions in this course about Scala/Java interop for futures or functions beyond correcting any errors in this material.
2019-07-17 Process Control Improved the answer to Exercise 1 - Reading Process Output into Memory.
2019-07-12   Completed updating all 748 HTML links in the 50 lecture transcripts that make up this course (some lectures have not been released yet). This was mostly a manual process. Please let us know of any errors or omissions. Note that Scala 2.13.0 does not provide Scaladoc for some classes, such as RichInt. This error should be rectified soon, possibly in time for Scala 2.1.3.1
2019-07-12 Implicit Classes Updated section Where to Put Implicit Definitions? for Scala 2.13.0.
2019-07-12 Combinators Updated transcript to Scala 2.13
2019-07-12 Higher-Order Functions Updated transcript to Scala 2.13.
2019-07-12 Mutable Collections Updated transcript for Scala 2.13.
2019-07-12 Sorting and Ordered Collections Updated math.Ordering.Implicits section of the transcript for Scala 2.13.
2019-07-11 Parametric Variance and Bounds Updated Exercise - Create a Failure-Proof init Method for Scala 2.13 and provided the solution in NoFailInit.scala in the git repo.
2019-07-11 Introduction to Collections Added Breaking Changes with Scala 2.13 section.
2019-07-09 Immutable Collections Added sections on Iterator.iterate, Iterator.fill, Iterator.tabulate and Iterator.unfold.
2019-07-07 To Converters Renamed lecture from Collection Converters to To Converters because most of the Scala 2.13 converters are now discussed in the new scala.jdk Converter Libraries lecture. Rewrote the type conversion information that comprises the first portion of the transcript.
2019-07-07 Collection Converters Added new sections: DurationConverters, FunctionConverters and FutureConverters. Also provided a new code example in the git repository demonstrating how to convert a Java CompleteableFuture to Scala.
2019-07-06 Collection Converters Added new section Option Converters
2019-07-05 MultiThreading Added link to a detailed history of the context switch mechanism on Linux.
2019-07-03 Mutable Collections Updated links to Parallel collections Scaladoc entries.
2019-07-03 Immutable Collections Updated links to Parallel collections Scaladoc entries.
2019-07-03 Parallel Collections Added location of Scaladoc for Parallel Collections and updated links to parallel collections Scaladoc entries.
2019-07-03 Introduction to Collections Rewrote and reorganized the lecture material.
2019-07-02 Collection Converters Rewrote the type conversion information that comprises the first portion of the transcript.
2019-07-02 Introduction to Collections Added new section to transcript: The IterableOnce and IterableOps Traits.
2019-07-02 Collection Converters Rewrote the introductory section in the transcript on Type Conversion.
2019-07-02   Added a new sbt project to the sample code git repo: compatLibDemo, which demonstrates the 2.13 Collection Compatibility Library.
2019-07-02 Introduction to Collections Added new section to the transcript: Scala 2.13 Collection Compatibility Library And Migration Tool
2019-07-02 Pattern Matching on Collections Added new section to the transcript: Scala 2.13's Pattern Matching on String
2019-07-01 Future Combinators Republished video for Scala 2.13
2019-06-30 Working With Collections of Futures Republished video for Scala 2.13
2019-06-27 Future Callbacks Republished video for Scala 2.13
2019-06-26 Parallel Collections Republished video for Scala 2.13
2019-06-25 Immutable Collections Added section on Scala 2.13's new SeqMap trait
2019-06-24 Introduction to Collections Added a few missing classes to the UML diagrams of the Scala 2.13 collection classes
2019-06-17 Introduction to Collections The portions of the transcript that used to discuss Traversable now discuss Iterable.
2019-06-17 Introduction to Collections Updated the UML Diagrams of Scala Collection Classes to Scala 2.13
2019-06-17 Sorting and Ordered Collections Added new section for Scala 2.13's TotalOrderings for Float and Double
2019-06-17 Introduction to Collections Updated the Table of Scala Collection Types for Scala 2.13
2019-06-17 Working With Collections of Futures Using Future.foldLeft and Future.reduceLeft instead of Future.fold and reduce for Scala 2.13
2019-06-17 Future Combinators Modified fold and reduce method references to foldLeft and reduceLeft for Scala 2.13
2019-06-17 Scala I/O New section added that discourages the use of io.Source in favor of the using method for input and output
2019-06-17 Immutable Collections Rewrote Stream section of transcript and renamed it to LazyList
2019-06-17 Collection Converters Added Scala 2.13's scala.jdk.CollectionConverters and added a new section about Converter History
2019-06-17 Parallel Collections Renamed Looking Ahead to Scala 2.13 section to Scala 2.13 Changes
2019-06-12 Sample code Updated sample code for the entire course and all dependencies to Scala 2.13.0.
2019-05-01 Getting Results from Futures & Signaling with Promises Discussed how Swatcher has been abandoned, and so the OnCreate sample project is stuck at Scala 2.12.x.
2019-04-20 Immutable Collections Added a mention of Scala 2.13's LazyList
2019-04-20 Parallel Collections Added new section entitled "Looking Ahead to Scala 2.13"
2018-04-09 HOCON Configuration Updated to PureConfig 0.9.1
2018-02-14 Implicit Values Added reference to SIP-35 (Opaque Types)
2017-06-16 Parametric Types Added section Parameters with Abstract Classes vs Traits to transcript.
2017-06-05 Introduction to Actors Replaced ActorSystem.shutdown with ActorSystem.terminate
2017-06-05 Akka ActorSystem Replaced ActorSystem.shutdown with ActorSystem.terminate, and added code examples
2017-06-05 Process Control Added another more detail for Process.apply
2017-02-24 HOCON Configuration Modified the list of HOCON wrappers at the end of the lecture to only include actively supported projects
2017-02-21 Scala I/O Added a code example for Scala 2.12's new io.Source.fromResource to the transcript.
2017-02-09 Parametric Variance and Bounds Updated to use new Scala Type Hierarchy diagram and republished video
2016-12-05 All Updated code examples to Scala 2.12.1
2016-11-09 All Updated code examples to Scala 2.12
2016-10-29 Parametric Types Updated video to match transcript
2016-10-28 Introduction to Collections Reworked transcript and video
2016-10-26 Implicit Conversions Updated video to match transcript
2016-10-26 Parametric Variance and Bounds Updated video to match transcript
2016-10-25 Structural Types Updated video to match transcript
2016-10-24 Immutable Collections Reworked transcript, added several sections, republished video
2016-10-24 For-Loops and For-Comprehensions Examples Added Short-Circuiting and Short-Circuiting a for-comprehension sections
2016-10-24 For-Loops and For-Comprehensions Added Short Circuiting section
2016-10-15 Implicit Conversions Added another example to the Coercion by Implicit Conversions section
2016-10-15 For-Loops and For-Comprehensions Examples Rewrote Either is Not Right-Biased section for Scala 2.12 and renamed it Either is Right-Biased With Scala 2.12.
2016-10-13 HOCON Configuration Reworked lecture and updated video
2016-10-11 Scala I/O Reworked entire lecture and republished video
2016-10-09 Getting Results from Futures & Signaling with Promises Reworked transcript and video so it flows better
2016-10-08 Combinators Updated video to match transcript
2016-10-08 MultiThreading Added additional information on task switch overhead and updated video to match transcript
2016-09-29 Introduction to Collections Added reference to Benchmarking Scala Collections article
2016-09-14 MultiThreading Added graphic showing 'Not all CPU operations are created equal'
2016-08-28 Combinators Added section Use Intermediate Variables and Declare Their Types to transcript
2016-08-27 HOCON Configuration Rearranged material and added Arrays of Properties section to transcript
2016-08-01 HOCON Configuration Added a discussion of the resolve method
2016-07-24 Implicit Values Added SLS 7.1 section to transcript
2016-06-28 MultiThreading Mentioned scala.concurrent.forkjoin.ForkJoinPool was deprecated by Scala 2.12
2016-03-30 Implicit Classes Republished video
2016-03-11 Parametric Types Reworked transcript and published a new video
2016-03-11 Implicit Classes Added reference to the Parametric Traits as Rich Interfaces of the Parametric Types lecture
2016-03-10 For-Loops and For-Comprehensions Added Extraction section to transcript
2016-03-09 Future Callbacks Updated to Scala 2.12 and republished video
2016-03-02 Higher-Order Functions Updated Exercise – Using the Predefined WrappedString Implicit Class to Scala 2.11.8 and republished video
2016-03-02 Combinators Heavily edited lecture and republished video
2016-03-02 For-Loops and For-Comprehensions Completely rewrote lecture transcript and republished video
2016-01-31 For-Loops and For-Comprehensions Added Desugaring with Quasiquotes section.
2015-12-29 Combinators Improved flatMap section in transcript
2015-12-10 HOCON Configuration Added Generating JSON section to transcript.
2015-12-01 MultiThreading Added section ThreadLocal vs. Fork-Join to transcript
2015-11-19 Implicit Conversions Updated video with Methods as Implicit Values section
2015-11-18 Immutable Collections Added a discussion of complexity for immutable.List operations
2015-11-07 MultiThreading Updated most of the links to Java, Akka and Scala docs
2015-10-21 Future Callbacks Updated for Scala v2.12-M3
2015-10-12 Implicit Values Updated transcript and republished video
2015-10-11 Implicit Conversions Added Methods as Implicit Values section
2015-10-10 Parametric Types Added Scala 2.12 @implicitAmbiguous section
2015-09-23 Partial Functions Added lift and unlift sections and reworked entire video.
2015-09-20 Partially Applied Functions Rewrote the last section and broke it into two sections: AntiPatterns: Eager Evaluation and Closing Over External State and Pattern: Designing Layered Software, republished video with many other improvements.
2015-09-17 Using Partially Applied Functions Numerous changes to transcript and republished video
2015-08-11 Introduction to Collections Added UML Diagrams of Scala 2.11 Collection Classes
2015-08-06 Partial Functions Added the AndThenTry exercise and More Than Two Cases to Handle Try section to the transcript, and republished video. Also added two portions of code from this lecture to the scalacourses-utils project.
2015-07-11 Parametric Variance and Bounds Added new exercise: Create a Failure-Proof init Method
2015-07-11 Immutable Collections Improved the failure-proof init example
2015-07-08 Combinators Added exercise Exercise - HTTP URL-Form Encoded Parameters
2015-06-15 For-Loops and For-Comprehensions Examples Added Either is Not Right-Biased section to transcript.
2015-05-24 Partially Applied Functions Enhanced the Partially Applying the apply Method section in the transcript
2015-04-22 Implicit Values Added section Using implicitly To Resolve Implicit Parameters to the transcript
2015-03-11 Pattern Matching on Collections Expanded transcript and published video
2015-03-10 Pattern Matching on Sequences Added new exercise Extract File Type from Path to end of lecture
2015-03-10 Future Callbacks Republished video
2015-03-08 Future Callbacks Added method signatures to the Callback Methods section, and enhanced the discussion
2015-03-06 Working With Collections of Futures Renamed repository from futurePerfect to scalacourses-utils.
2015-03-05 Memoization in Depth Published first version of transcript and code examples
2015-02-23 Implicit Classes Added Yet Another Example and Comprehensive Example
2015-02-23 Implicit Classes Added new section to the transcript: Where to Put Implicit Definitions?
2015-02-20 Implicit Values Added This Lecture Introduces Two Concepts section to the transcript
2015-02-11 Partially Applied Functions Added Revisiting the Handmade unless Construct section to the transcript
2015-02-03 Introduction to Actors Published video
2015-01-30 Akka ActorSystem Published video
2015-01-29 Future Bad Habits and Exercise Published video
2015-01-27 Working With Collections of Futures Published video
2015-01-20 Sorting and Ordered Collections Video & transcript greatly enhanced; 50% longer
2015-01-14 Partial Functions Added Trying Harder Exercise
2015-01-11 Future Combinators Published video
2015-01-08 For-comprehensions With Futures Published video
2015-01-07 Future Callbacks Published video
2015-01-03 Immutable Collections Added About the foreach section for Iterator.continually example
2015-01-03 Getting Results from Futures & Signaling with Promises Published video
2015-01-01 Parametric Types Enhanced the transcript for the Parametric Traits as Rich Interfaces example
2015-01-01 Introduction to Actors Moved the sample code to the multi package
2015-01-01 Akka ActorSystem Moved the sample code to the multi package
2015-01-01 Future Bad Habits and Exercises Moved the sample code to the multi/futures package
2015-01-01 Working With Collections of Futures Moved the sample code to the multi/futures package
2015-01-01 Future Combinators Moved the sample code to the multi/futures package
2015-01-01 Future For-comprehensions Moved the sample code to the multi/futures package
2015-01-01 Getting Results from Futures & Signaling with Promises Moved the sample code to the multi/futures package
2015-01-01 Future Callbacks Moved the sample code to the multi/futures package
2015-01-01 Futures & Promises Moved the sample code to the multi/futures package
2015-01-01 Parallel Collections Moved the sample code to the multi package
2015-01-01 Higher-Order Functions Corrected video and transcript for the Timing a Task section
2014-11-21 Implicit Values Added Strongly Typed Method Parameters section to Value Classes discussion
2014-11-19   Updated courseNotes project to SBT 0.13.7
2014-11-13 Futures & Promises Published video
2014-11-12 Parallel Collections Published video
2014-11-04 Parametric Variance and Bounds Published video
2014-11-01   Updated sample code to Scala 2.11.4
2014-10-19 Partial Functions Published video
2014-10-16 MultiThreading Published video
2014-10-11   Updated sample code to Scala 2.11.3
2014-10-07 Working With Collections of Futures Added Processing Futures As They Complete and Canceling Futures sections
2014-10-07 For-Loops and For-Comprehensions Added Can't Mix Monads section to the transcript.
2014-10-01 Partial Functions Updated lecture for recording
2014-10-01 Working With Collections of Futures Hived from Combinators and Collections, renamed that lecture to Combinators
2014-10-01 Getting Results from Futures & Signaling with Promises Hived from the Future Callbacks, Results & Signaling with Promises lecture, and renamed that lecture to Future Callbacks
2014-09-30 Combinators Added short section to the transcript discussing the identity transformation
2014-09-29 MultiThreading Added Runtime ExecutionContext Selector section to transcript.
2014-09-22 Future Bad Habits and Exercise Hived this lecture from Futures & Promises
2014-09-22 Future For-comprehensions, Combinators, Collections & Failure Hived this lecture from Futures & Promises
2014-09-22 Future Callbacks, Results & Signaling with Promises Hived this lecture from Futures & Promises
2014-09-22 Futures & Promises Updated material and split into four lectures
2014-09-18 Sorting and Ordered Collections Added Enumeration Value Sets section
2014-09-18 Using Partially Applied Functions Fixed compile error in courseNotes/src/main/scala/solutions/DBOps.scala
2014-09-16 Immutable Collections Updated transcript: Added discussions on type hints, expanded the discussion of Nil into an entire section, and provided guidelines on using headOption, tailOption, lastOption and drop instead of head, tail, last and init.
2014-09-12 Using Partially Applied Functions Improved the Wrapping Database Operations With the Loan Pattern Exercise
2014-08-30 Introduction to Collections Recorded new 5 minute video section for Custom String Interpolation section
2014-08-24 Introduction to Collections Added Defining Custom String Interpolation to Access a Map section to transcript
2014-08-15 Combinators Added Writing for Clarity section
2014-08-11 Using Partially Applied Functions Published video
2014-08-09 Partially Applied Functions Published video
2014-08-09 Using Partially Applied Functions Hived this lecture from the Partially Applied Functions lecture
2014-08-04 Structural Types Published video
2014-07-19 Combinators Updated video, now includes an 8 minute long section on Idioms
2014-07-15 Combinators Added Idioms section to transcript, addressing writing style.
2014-07-12 Futures Added a comprehensive example (Cross-Context Signaling with Promises) showing how to use a Promise to clean up Java callbacks.
2014-07-05 Process Control Added an example of Scala process control calling a command with arguments and passing an environment variable, and republished the video.
2014-06-22   Updated brew install incantation in this page.
2014-06-22 Parametric Types Added section and code examples for scoped and shadowed type parameters.
2014-06-21 Typesafe Config Exercise and Extended Example Published video.
2014-06-20 Typesafe Config Published video.
2014-06-11 For-Loops and For-Comprehensions Examples Added For-Comprehension of Trys example and republished video.
2014-06-13   Updated courseNotes and solutions SBT projects to Scala 2.11.1.
2014-06-12 Extended Example of For-Comprehensions Published video.
2014-06-11 For-Loops and For-Comprehensions Examples Published video.
2014-06-11 For-Loops and For-Comprehensions Added map/orElse idiom to transcript and republished video.
2014-06-11 Introduction to Collections Added Map.getOrElse to transcript.
2014-04-13 For-Loops and For-Comprehensions
For-Loops and For-Comprehensions Examples
Extended Example of For-Comprehensions
Updated transcript, released new video, moved examples and quizzes into 2 new lectures, which follow.
2014-06-04 Combinators Updated video.
2014-04-18 Sorting and Ordered Collections Published video.
2014-03-31   Updated courseNotes project to Scala 2.10.4.
2014-04-15 Introduction to Collections
Immutable Collections
Mutable Collections
Collection Converters
Overly long collections lecture split into smaller, more focused lectures.
2014-03-28   Updated Course Notes PDF provided in git repository.
2014-03-28 Parallel Collections Added solution for exercise.
2014-03-21 Typesafe Config Wrote transcript.
2013-09-18 Implicit Values
Implicit Conversions
Implicit Classes
Split long lecture into more focused, smaller lectures.
2013-09-15 Scala I/O Wrote transcript.
2013-03-14 Sorting and Ordered Collections Wrote transcript.
2014-03-12 Combinators Added discussion of monads.
2013-10-21 Partially Applied Functions Wrote transcript.
2013-09-14 Concurrency
Futures
Introduction to Actors
Updated transcripts and sample code.
2013-09-10   Early access program started.
2012-12-14   Initial course setup.
Price: $100usd
Instructor(s): ,