├── .gitignore
├── LICENSE.md
├── README.md
├── build.sbt
├── project
├── build.properties
└── plugins.sbt
└── src
├── jekyll
├── _config.yml
├── _includes
│ ├── head.html
│ ├── simpleslide.html
│ └── slide.html
├── _layouts
│ ├── default.html
│ ├── presentation.html
│ ├── print.html
│ └── simplepresentation.html
├── _posts
│ ├── .gitinclude
│ ├── 2012-1-1-intro.md
│ ├── 2012-1-2-about.md
│ ├── 2012-1-3-agenda.md
│ ├── 2012-1-4-define.md
│ ├── 2012-1-4-pure.md
│ ├── 2012-1-5-pure-example.md
│ ├── 2012-1-6-why-rt.md
│ ├── 2012-1-7-a-reason-to-care.md
│ ├── 2012-1-8-algorithm.md
│ ├── 2012-2-1-building-blocks.md
│ ├── 2012-2-2-a-start.md
│ ├── 2012-2-3-thread-usage.md
│ ├── 2012-3-1-adding-map.md
│ ├── 2012-3-2-using-map.md
│ ├── 2012-3-3-thread-usage.md
│ ├── 2012-3-4-nesting-issue.md
│ ├── 2012-4-1-adding-flatmap.md
│ ├── 2012-4-2-fixing-nesting.md
│ ├── 2012-4-3-thread-usage.md
│ ├── 2012-4-4-sequencing-issue.md
│ ├── 2012-5-1-adding-traverse.md
│ ├── 2012-5-2-thread-usage.md
│ ├── 2012-5-3-using-traverse.md
│ ├── 2012-6-1-adding-zip.md
│ ├── 2012-6-2-using-zip.md
│ ├── 2012-6-3-some-sugar.md
│ ├── 2012-6-4-what-about-testing.md
│ ├── 2012-7-1-abstracting-the-patterns.md
│ ├── 2013-1-1-functors.md
│ ├── 2013-2-1-monads.md
│ ├── 2013-3-1-applicative-functor.md
│ ├── 2013-4-1-traverse.md
│ ├── 2014-1-1-refactor-api.md
│ ├── 2014-1-2-refactor-service.md
│ ├── 2014-1-3-single-threaded.md
│ ├── 2014-1-4-single-threaded-instance.md
│ ├── 2014-1-5-single-threaded-applicative.md
│ ├── 2014-1-6-single-threaded-applicative.md
│ ├── 2014-2-1-the-test.md
│ ├── 2015-1-1-conclussions.md
│ ├── 2015-1-2-questions.md
│ └── slide_template.md
├── _sass
│ ├── config.rb
│ ├── hekyll.scss
│ └── partials
│ │ ├── _base.scss
│ │ ├── _elements.scss
│ │ └── _variables.scss
├── cover.png
├── css
│ ├── animations.css
│ ├── custom.css
│ ├── fonts
│ │ ├── roboto-regular-webfont.eot
│ │ ├── roboto-regular-webfont.svg
│ │ ├── roboto-regular-webfont.ttf
│ │ ├── roboto-regular-webfont.woff
│ │ └── roboto.css
│ ├── hekyll.css
│ └── syntax.css
├── impress.js
├── index.md
├── preso.html
├── print.html
└── simple-preso.html
├── main
└── scala
│ ├── futures
│ ├── App.scala
│ ├── api.scala
│ └── service.scala
│ ├── generic
│ ├── App.scala
│ ├── abstractions.scala
│ ├── api.scala
│ ├── contexts.scala
│ ├── ghservice.scala
│ ├── instances.scala
│ ├── service.scala
│ └── syntax.scala
│ └── model
│ └── model.scala
├── site
└── .nojekyll
└── test
└── java
├── futures
└── ServiceSpec.scala
└── generic
└── ServiceSpec.scala
/.gitignore:
--------------------------------------------------------------------------------
1 | _drafts/
2 | _site/
3 | .DS_Store
4 | *.swo
5 | *.swp
6 | .sass-cache
7 | target
8 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | Copyright (c) 2012, Joshua Suereth
2 | All rights reserved.
3 |
4 |
5 | ## Slides ##
6 | All slides are released [Creative Commons Attribution 3.0](http://creativecommons.org/licenses/by/3.0/us/)
7 |
8 | This work is licensed under a Creative Commons Attribution 3.0 United States License .
9 |
10 | ## Code ##
11 | All code is released under the Apache License v2.0.
12 |
13 |
14 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
15 |
16 | Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
17 | Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
19 |
20 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Introduction to Functional Programming Patterns #
2 | _in Scala_
3 |
4 | Authored by: Josh Suereth (jsuereth)
5 |
6 | ## Description ##
7 |
8 | Asycnhronous APIs are all the rage, however most APIs remain clunky. This talk embarks on journey to glue together some asynchronous calls in a way that is still asynchronous. After acheiving the concurrent nirvana, one is faced with the issue of testing. With a few simple functional abstractions, the same code can be used in both a synchronous and asynchronous manner.
9 |
10 | In particular, [this talk](http://jsuereth.com/intro-to-fp) covers:
11 |
12 | * Monadic workflows
13 | * Applicative Functors and joined computation
14 | * Essence of Iteration
15 |
16 | As seen in the Akka futures library.
17 |
18 | ## Requirements ##
19 |
20 | - sbt(0.11.3)
21 | - Jekyll
22 |
23 | ## Acknowledgements ##
24 |
25 | Thanks to all my FP peeps who drilled this stuff into me until I realized it was useful.
26 |
27 | This presentation uses:
28 |
29 | - [hekyll](https://github.com/bmcmurray/hekyll)
30 | - [impress.js](https://github.com/bartaz/impress.js)
31 | - [Jekyll](https://github.com/mojombo/jekyll)
32 | - [Simple Build Tool](https://github.com/harrah/xsbt)
33 | - [Scala](https://github.com/scala/scala)
34 |
35 | ## Resources ##
36 |
37 | - [Scala in Depth](http://manning.com/suereth)
38 | - [Scala documentation](http://docs.scala-lang.org)
39 | - [Akka documentation](http://akka.io/docs/)
40 | - [Essence of the Iterator Pattern](http://www.cs.ox.ac.uk/jeremy.gibbons/publications/iterator.pdf)
41 | - [Blog: Essence of Iterator Pattern](http://etorreborre.blogspot.com/2011/06/essence-of-iterator-pattern.html)
42 |
43 |
44 | # LICENSE #
45 |
46 | Copyright (c) 2012, Joshua Suereth
47 | All rights reserved.
48 |
49 |
50 | ## Slides ##
51 | All slides are released [Creative Commons Attribution 3.0](http://creativecommons.org/licenses/by/3.0/us/)
52 |
53 | This work is licensed under a Creative Commons Attribution 3.0 United States License .
54 |
55 | ## Code ##
56 | All code is released under the Apache License v2.0.
57 |
58 |
59 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
60 |
61 | Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
62 | Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
63 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 |
--------------------------------------------------------------------------------
/build.sbt:
--------------------------------------------------------------------------------
1 | name := "intro-to-fp"
2 |
3 | organization := "com.jsuereth"
4 |
5 | site.settings
6 |
7 | site.jekyllSupport()
8 |
9 | com.jsuereth.sbtsite.SiteKeys.siteMappings <<= com.jsuereth.sbtsite.SiteKeys.siteMappings map { m =>
10 | for {
11 | (file, target) <- m
12 | if (target startsWith "css/") || !(target contains "/")
13 | } yield file -> target
14 | }
15 |
16 | resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"
17 |
18 | scalaVersion := "2.10.2-RC2"
19 |
20 | libraryDependencies ++= Seq(
21 | "com.typesafe.akka" %% "akka-actor" % "2.2.0-RC1",
22 | "net.databinder.dispatch" %% "dispatch-core" % "0.10.1",
23 | "org.specs2" %% "specs2" % "2.0-RC1" % "test"
24 | )
25 |
26 | scalacOptions += "-optimise"
27 |
28 | ghpages.settings
29 |
30 | git.remoteRepo := "git@github.com:jsuereth/intro-to-fp.git"
31 |
--------------------------------------------------------------------------------
/project/build.properties:
--------------------------------------------------------------------------------
1 | sbt.version=0.12.3
2 |
--------------------------------------------------------------------------------
/project/plugins.sbt:
--------------------------------------------------------------------------------
1 | resolvers += Resolver.url("sbt-plugin-releases", new URL("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases/"))(Resolver.ivyStylePatterns)
2 |
3 | resolvers += "jgit-repo" at "http://download.eclipse.org/jgit/maven"
4 |
5 | addSbtPlugin("com.jsuereth" % "sbt-ghpages-plugin" % "0.4.0")
--------------------------------------------------------------------------------
/src/jekyll/_config.yml:
--------------------------------------------------------------------------------
1 | pygments: true
2 | permalink: "/:title"
3 |
4 | ## Hekyll Configuration ##
5 | overview: true # true/false -- enabling this will add an overview slide at the end of the presentation. The overview slide will not display if simple-slideshow, above, is enabled.
6 | overview-data:
7 | x: 1000 # integer -- set this to the center x point of the overview slide, usually the center of your slide canvas area
8 | y: 1000 # integer -- set this to the center y point of the overview slide, usually the center of your slide canvas area
9 | scale: 15 # integer -- set the scale of the overview slide, usually far enough back to fit everything in view
10 |
--------------------------------------------------------------------------------
/src/jekyll/_includes/head.html:
--------------------------------------------------------------------------------
1 |
2 |
{{ page.title }}
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/src/jekyll/_includes/simpleslide.html:
--------------------------------------------------------------------------------
1 |
2 | {% if post.title != "" %}
{{ post.title }} {% endif %}
3 |
4 | {{ post.content }}
5 |
6 |
--------------------------------------------------------------------------------
/src/jekyll/_includes/slide.html:
--------------------------------------------------------------------------------
1 |
2 | {% if post.title != "" %}
{{ post.title }} {% endif %}
3 |
4 | {{ post.content }}
5 |
6 |
--------------------------------------------------------------------------------
/src/jekyll/_layouts/default.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {% include head.html %}
5 |
6 |
7 |
8 |
9 | {{ content }}
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/jekyll/_layouts/presentation.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {% include head.html %}
5 |
6 |
7 |
8 | {{ content }}
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/jekyll/_layouts/print.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {% include head.html %}
5 |
6 |
7 |
8 | {{ content }}
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/jekyll/_layouts/simplepresentation.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {% include head.html %}
5 |
6 |
7 |
8 | {{ content }}
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/jekyll/_posts/.gitinclude:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsuereth/intro-to-fp/5feab100c06a4feb3af2b9e675c6217e6fb5764a/src/jekyll/_posts/.gitinclude
--------------------------------------------------------------------------------
/src/jekyll/_posts/2012-1-1-intro.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: slide
3 | title: ""
4 | published: true
5 | data:
6 | x: 0
7 | y: 0
8 | z: -3000
9 | scale: 18
10 |
11 | ---
12 |
13 | # Functional Programming #
14 | _Patterns in Scala_
15 |
--------------------------------------------------------------------------------
/src/jekyll/_posts/2012-1-2-about.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: slide
3 | title: ""
4 | published: true
5 | data:
6 | x: -3400
7 | y: -500
8 | rotate: 0
9 | scale: 5
10 |
11 | ---
12 |
13 | # Who am I? #
14 |
15 | * Author
16 | * Blogger
17 | * Software Developer
18 | * Scala committer
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/src/jekyll/_posts/2012-1-3-agenda.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: ""
4 | published: true
5 | data:
6 | x: 2400
7 | y: 0
8 | rotate: -25
9 |
10 | ---
11 |
12 | # Agenda #
13 |
14 | * Define Functional Programming
15 | * A Github User Statistics Calculator
16 | * Asynchronous mapping
17 | * Asynchronous traversal
18 | * Joining computations
19 | * Testing Synchronous + FP Patterns
20 |
--------------------------------------------------------------------------------
/src/jekyll/_posts/2012-1-4-define.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: ""
4 | published: true
5 | data:
6 | x: 3350
7 | y: 350
8 | rotate: 25
9 | ---
10 |
11 | # Definition #
12 |
13 | Functional Programming is the *composition* of *behavior* using *pure* functions.
14 |
--------------------------------------------------------------------------------
/src/jekyll/_posts/2012-1-4-pure.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: ""
4 | published: true
5 | data:
6 | x: 3750
7 | y: 950
8 | rotate: 30
9 | z: -1000
10 | ---
11 |
12 | # Pure Functions #
13 |
14 | Functions that are *referentially transparent*.
15 | * We can *repeatedly* produce the same output from the same input.
16 | * We can *Substitute* result of a function
17 |
--------------------------------------------------------------------------------
/src/jekyll/_posts/2012-1-5-pure-example.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: ""
4 | published: true
5 | data:
6 | x: 4250
7 | y: 1750
8 | rotate: 25
9 | scale: 1
10 | ---
11 |
12 | # Which one is RT? #
13 |
14 | {% highlight scala %}
15 | def plus(x: Int, y: Int) =
16 | x + y
17 | {% endhighlight %}
18 |
19 |
20 |
21 | vs.
22 |
23 |
24 |
25 | {% highlight scala %}
26 | def log(msg: String): Unit =
27 | logfile println wrap(msg)
28 | {% endhighlight %}
29 |
30 |
--------------------------------------------------------------------------------
/src/jekyll/_posts/2012-1-6-why-rt.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: ""
4 | published: true
5 | data:
6 | x: 4750
7 | y: 2250
8 | z: -1000
9 | rotate: 40
10 | ---
11 |
12 | # Why stay pure? #
13 |
14 | * Easier to *test* the code
15 | * Easier to *reason* what a function does. *No surprises!*
16 | * Easier to go *concurrent*
17 | * Easier to *compose* functionality.
18 |
--------------------------------------------------------------------------------
/src/jekyll/_posts/2012-1-7-a-reason-to-care.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: ""
4 | published: true
5 | data:
6 | x: 5350
7 | y: 2850
8 | z: 0
9 | rotate: 50
10 | ---
11 |
12 | # A reason to care #
13 |
14 | Imagine you're *gluing* together a set of *services*.
15 |
16 | Each call to service is an *asynchronous* network operation.
17 |
18 | Some operations can be run in *parallel*.
19 |
20 | We have a *high load* on the server and want to *prevent blocking*.
21 |
22 |
23 |
--------------------------------------------------------------------------------
/src/jekyll/_posts/2012-1-8-algorithm.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: ""
4 | published: true
5 | data:
6 | x: 5550
7 | y: 2450
8 | z: 1200
9 | rotate: 0
10 | ---
11 |
12 | # Basic Outline #
13 |
14 | Collecting statistics for a given github user
15 |
16 | * For every *project* a user owns
17 | 1. Collect all *pull requests*
18 | 2. Collect all *watchers*
19 | * Aggregate results into a *popularity score*
20 |
--------------------------------------------------------------------------------
/src/jekyll/_posts/2012-2-1-building-blocks.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: ""
4 | published: true
5 | data:
6 | x: 5550
7 | y: 2000
8 | z: 2400
9 | rotate: 0
10 | ---
11 |
12 | # A few building blocks #
13 |
14 | {% highlight scala %}
15 | trait Future[A] {
16 | def isDone: Boolean
17 | def await: A
18 | }
19 | {% endhighlight %}
20 |
21 | {% highlight scala %}
22 | trait GithubService {
23 | def projects(user: User): Future[Seq[Project]]
24 | def pullreqs(project: Project): Future[Seq[PullRequest]]
25 | def watchers(project: Project): Future[Seq[User]]
26 | }
27 | {% endhighlight %}
28 |
--------------------------------------------------------------------------------
/src/jekyll/_posts/2012-2-2-a-start.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: ""
4 | published: true
5 | data:
6 | x: -750
7 | y: -1650
8 | rotate: -50
9 | z: 3400
10 | ---
11 |
12 | # A first start #
13 |
14 |
def getStatistics(user: User ): Statistics = {
15 | val projects = api.projects(user).await
16 | var reqs = Seq.empty[PullRequest ]
17 | var watchers = Seq.empty[User ]
18 | for (project <- projects) {
19 | reqs ++= api.pullreqs(project).await
20 | watchers ++= api.watchers(project).await
21 | }
22 | Statistics(user, reqs, watchers)
23 | }
24 |
--------------------------------------------------------------------------------
/src/jekyll/_posts/2012-2-3-thread-usage.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: ""
4 | published: true
5 | data:
6 | x: -50
7 | y: -2150
8 | rotate: -10
9 | z: 3390
10 | ---
11 |
12 | # A first start - Threading #
13 |
14 |
--------------------------------------------------------------------------------
/src/jekyll/_posts/2012-3-1-adding-map.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: ""
4 | published: true
5 | data:
6 | x: -50
7 | y: -2150
8 | z: 2000
9 | rotate: -10
10 | ---
11 |
12 | # Adding some Asynch #
13 |
14 | {% highlight scala %}
15 | trait Future[A] {
16 | def map(f: A => B): Future[B]
17 | }
18 | {% endhighlight %}
19 |
--------------------------------------------------------------------------------
/src/jekyll/_posts/2012-3-2-using-map.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: ""
4 | published: true
5 | data:
6 | x: -750
7 | y: -1650
8 | z: 2000
9 | rotate: -50
10 | ---
11 |
12 | # More Asynch? #
13 | def getStatistics(user: User ): Future [Statistics] =
14 | api.projects(user) map { projects =>
15 | var reqs = Seq.empty[PullRequest ]
16 | var watchers = Seq.empty[User ]
17 | for (project <- projects) {
18 | reqs ++= api.pullreqs(project).await
19 | watchers ++= api.watchers(project).await
20 | }
21 | Statistics(user, reqs, watchers)
22 | }
23 |
--------------------------------------------------------------------------------
/src/jekyll/_posts/2012-3-4-nesting-issue.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: ""
4 | published: true
5 | data:
6 | x: 1150
7 | y: -950
8 | z: 2000
9 | rotate: 40
10 | ---
11 |
12 | # Nesting! #
13 |
14 | {% highlight scala %}
15 | val projects: Future[Seq[Project]] =
16 | api.projects(user)
17 |
18 | val firstpullreqs: Future[Future[Seq[PullRequests]]] =
19 | projects map { projects =>
20 | api.getpullreqs(projects.head)
21 | }
22 |
23 | val flattenedPullReqs: Future[Seq[PullRequests]] =
24 | ???
25 |
26 | {% endhighlight %}
27 |
--------------------------------------------------------------------------------
/src/jekyll/_posts/2012-4-1-adding-flatmap.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: ""
4 | published: true
5 | data:
6 | x: 450
7 | y: -1450
8 | rotate: 20
9 | z: 500
10 | ---
11 |
12 | # Chaining Asynchronous Calls #
13 |
14 | {% highlight scala %}
15 | object Future {
16 | def flatten[A](f: Future[Future[A]]): Future[A]
17 | }
18 | trait Future[A] {
19 | def flatMap(f: A => Future[B]): Future[B]
20 | }
21 | {% endhighlight %}
--------------------------------------------------------------------------------
/src/jekyll/_posts/2012-4-2-fixing-nesting.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: ""
4 | published: true
5 | data:
6 | x: 1050
7 | y: -950
8 | rotate: 40
9 | z: 500
10 | ---
11 |
12 | # A fix for nesting! #
13 |
14 | {% highlight scala %}
15 | val projects: Future[Seq[Project]] =
16 | api.projects(user)
17 |
18 | val firstpullreqs: Future[Seq[PullRequests]] =
19 | projects flatMap { projects =>
20 | api.getpullreqs(projects.head)
21 | }
22 |
23 | {% endhighlight %}
--------------------------------------------------------------------------------
/src/jekyll/_posts/2012-4-4-sequencing-issue.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: ""
4 | published: true
5 | data:
6 | x: -750
7 | y: -1650
8 | rotate: -50
9 | z: 500
10 | ---
11 |
12 | # Too much blocking #
13 |
14 | * I have a sequence of projects
15 | (Seq[Project]
)
16 | * I have an asynchronous operation on a project
17 | (Project => Future[Seq[PullRequests]]
)
18 | * I want an asynchronous collective result
19 | (Future[Seq[PullRequest]]
)
20 | * Should not block for every element of a collection!
--------------------------------------------------------------------------------
/src/jekyll/_posts/2012-5-1-adding-traverse.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: ""
4 | published: true
5 | data:
6 | x: -750
7 | y: -1650
8 | rotate: -50
9 | z: -1200
10 | ---
11 |
12 | # Traversing #
13 |
14 | {% highlight scala %}
15 | object Future {
16 | def traverse[A,B](values: Seq[A])(asynchOp: A => Future[B]): Future[Seq[B]]
17 | }
18 | {% endhighlight %}
--------------------------------------------------------------------------------
/src/jekyll/_posts/2012-5-2-thread-usage.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: ""
4 | published: true
5 | data:
6 | x: -50
7 | y: -2150
8 | rotate: -10
9 | z: -1200
10 | ---
11 |
12 | # Traversal and Threads #
13 |
14 |
--------------------------------------------------------------------------------
/src/jekyll/_posts/2012-5-3-using-traverse.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: ""
4 | published: true
5 | data:
6 | x: 1050
7 | y: -950
8 | rotate: 40
9 | z: -1200
10 | ---
11 |
12 | # Traversing #
13 |
14 | def getStatistics(user: User ): Future[Statistics] = {
15 | val projects: Future[Seq[Project]] =
16 | api.projects(user)
17 | val requests: Future[Seq[Seq[PullRequests]]] =
18 | projects flatMap { projects => Future.traverse (projects)(api.pullrequests) }
19 | val watchers: Future[Seq[Seq[User]]] =
20 | projects flatMap { projects => Future.traverse (projects)(api.watchers) }
21 | Statistics(user, requests.await.flatten , watchers.await.flatten )
22 | }
23 |
--------------------------------------------------------------------------------
/src/jekyll/_posts/2012-6-1-adding-zip.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: ""
4 | published: true
5 | data:
6 | x: 1250
7 | y: -950
8 | rotate: 40
9 | z: -2600
10 | ---
11 |
12 | # Zipping/Joining #
13 |
14 | {% highlight scala %}
15 | trait Future[A] {
16 | def zip[B](other: Future[B]): Future[(A,B)]
17 | }
18 | {% endhighlight %}
--------------------------------------------------------------------------------
/src/jekyll/_posts/2012-6-2-using-zip.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: ""
4 | published: true
5 | data:
6 | x: -50
7 | y: -2150
8 | rotate: -10
9 | z: -2600
10 | ---
11 |
12 | # Using zip #
13 |
14 | def getStatistics(user: User ): Future[Statistics] = {
15 | val projects: Future[Seq[Project]] = api.projects(user)
16 | val requests: Future[Seq[PullRequest]] =
17 | projects flatMap { projects =>
18 | Future.traverse (projects)(api.pullrequests)
19 | } map (_.flatten)
20 | val watchers: Future[Seq[User]] =
21 | projects flatMap { projects =>
22 | Future.traverse (projects)(api.watchers)
23 | } map (_.flatten)
24 | val together: Future[(Seq[PullRequest], Seq[User])] =
25 | reqs zip watchers
26 | together map { case (r, w) => Statistics(user, r, w) }
27 | }
28 |
--------------------------------------------------------------------------------
/src/jekyll/_posts/2012-6-3-some-sugar.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: ""
4 | published: true
5 | data:
6 | x: 450
7 | y: -1450
8 | rotate: 20
9 | z: -2600
10 | ---
11 |
12 | # Some sugar#
13 |
14 | def getStatistics(user: User ): Future[Statistics] = {
15 | val projects: Future[Seq[Project]] = api.projects(user)
16 | val requests: Future[Seq[PullRequest]] = for {
17 | ps <- projects
18 | requests <- Future.traverse(projects)(api.pullrequests)
19 | } yield requests.flatten
20 | val watchers: Future[Seq[User]] = ...
21 | for ((r,w) <- requests zip watchers)
22 | yield Statistics(user, r, w)
23 | }
24 |
--------------------------------------------------------------------------------
/src/jekyll/_posts/2012-6-4-what-about-testing.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: ""
4 | published: true
5 | data:
6 | x: 1600
7 | y: -450
8 | z: 2990
9 | rotate: 60
10 | ---
11 |
12 | # What about testing? #
13 |
14 | Want to test program logic not execution context.
15 |
16 | * Don't want to alter core logic code.
17 | * Avoid multi-threading in tests.
--------------------------------------------------------------------------------
/src/jekyll/_posts/2012-7-1-abstracting-the-patterns.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: ""
4 | published: true
5 | data:
6 | x: -750
7 | y: 2450
8 | rotate: 0
9 | z: -1400
10 | ---
11 |
12 | # Abstracting the Concepts #
13 |
14 | * Sequenced Computational Context (*flatMap*)
15 | * Joined Computation (*zip*)
16 | * Contextual Iteration (*traverse*)
--------------------------------------------------------------------------------
/src/jekyll/_posts/2013-1-1-functors.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: ""
4 | published: true
5 | data:
6 | x: 50
7 | y: 2250
8 | rotate: -20
9 | z: -1400
10 | ---
11 |
12 | # Functors #
13 |
14 | The *map* operation
15 |
16 | {% highlight scala %}
17 | trait Functor[Context[_]] {
18 | def map[A,B](
19 | value: Context[A],
20 | raw_function: A => B
21 | ): Context[B]
22 | }
23 | {% endhighlight %}
--------------------------------------------------------------------------------
/src/jekyll/_posts/2013-2-1-monads.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: ""
4 | published: true
5 | data:
6 | x: 650
7 | y: 1750
8 | rotate: -30
9 | z: -1400
10 | ---
11 |
12 | # Monads #
13 |
14 | The *flatMap* operation
15 |
16 | {% highlight scala %}
17 | trait Monad[Context[_]] {
18 | def point[A](raw_value: A): Context[A]
19 |
20 | def flatMap[A,B](
21 | value: Context[A],
22 | operation: A => Context[B]
23 | ): Context[B]
24 | }
25 | {% endhighlight %}
--------------------------------------------------------------------------------
/src/jekyll/_posts/2013-3-1-applicative-functor.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: ""
4 | published: true
5 | data:
6 | x: 1050
7 | y: 1250
8 | rotate: -60
9 | z: -1400
10 | ---
11 |
12 | # Applicative Functors #
13 |
14 | The *zip* operation
15 |
16 | {% highlight scala %}
17 | trait Applicative[Context[_]] {
18 | def point[A](raw_value: A): Context[A]
19 |
20 | def applyNested[A,B](
21 | value: Context[A],
22 | contexted_function: Context[A => B]
23 | ): Context[B]
24 | }
25 | {% endhighlight %}
--------------------------------------------------------------------------------
/src/jekyll/_posts/2013-4-1-traverse.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: ""
4 | published: true
5 | data:
6 | x: 1550
7 | y: 650
8 | rotate: -40
9 | z: -1400
10 | ---
11 |
12 | # Iteration #
13 |
14 | The *traverse* operation.
15 |
16 | {% highlight scala %}
17 | trait Traverse[Collection[_]] {
18 | def traverse[Context[_]: Applicative,A,B](
19 | collection: Collection[A],
20 | operation: A => Context[B]
21 | ): Context[Collection[B]]
22 | }
23 | {% endhighlight %}
--------------------------------------------------------------------------------
/src/jekyll/_posts/2014-1-1-refactor-api.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: ""
4 | published: true
5 | data:
6 | x: 1550
7 | y: 650
8 | rotate: -40
9 | z: 100
10 | ---
11 |
12 | # A mite o' refactoring #
13 |
14 | Generalize the github API trait
15 |
16 | {% highlight scala %}
17 | trait GhApi[Context[_]] {
18 | def projects(user: String): Context[Seq[Project]]
19 | def pullreqs(proj: Project): Context[Seq[PullRequest]]
20 | def watchers(proj: Project): Context[Seq[Watcher]]
21 | }
22 |
23 | class AsyncGhApi extends GhApi[Future] { ... }
24 |
25 | class TestingGhApi extends GhApi[SingleThreaded] { ... }
26 | {% endhighlight %}
--------------------------------------------------------------------------------
/src/jekyll/_posts/2014-1-2-refactor-service.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: ""
4 | published: true
5 | data:
6 | x: 650
7 | y: 1750
8 | rotate: -30
9 | z: 100
10 | ---
11 |
12 | # Generic Service #
13 |
14 | {% highlight scala %}
15 | class GenericStatisticsService[Context[_]: Monad](api: GhApi[Context]) {
16 | def statistics(user: String): Context[Statistics] = {
17 | val projects = api.projects(user)
18 | def get[B](f: Project => Context[Seq[B]]): Context[Seq[B]] = for {
19 | ps <- projects
20 | items <- ps traverse f
21 | } yield items.flatten
22 | val pullRequests = get(api.pullrequests)
23 | val watchers = get(api.watchers)
24 | (pullRequests zip watchers) map { case (prs, ws) => Statistics(user, ws, prs)}
25 | }
26 | }
27 | {% endhighlight %}
--------------------------------------------------------------------------------
/src/jekyll/_posts/2014-1-3-single-threaded.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: ""
4 | published: true
5 | data:
6 | x: -750
7 | y: 2450
8 | rotate: 0
9 | z: 100
10 | ---
11 |
12 | # What is a SingleThreaded context? #
13 |
14 | {% highlight scala %}
15 | object Contexts {
16 | type SingleThreaded[A] = A
17 | type Future[A] = akka.dispatch.Future[A]
18 | }
19 | {% endhighlight %}
--------------------------------------------------------------------------------
/src/jekyll/_posts/2014-1-4-single-threaded-instance.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: ""
4 | published: true
5 | data:
6 | x: 50
7 | y: 2250
8 | rotate: -20
9 | z: 1500
10 | ---
11 |
12 | # SingleThreaded Functor #
13 |
14 | *map* method
15 |
16 | {% highlight scala %}
17 | def map[A,B](a: SingleThreaded[A])(f: A => B): SingleThreaded[B] =
18 | {% endhighlight %}
19 |
20 | Since `SingleThreaded[A]` *is* `A`, `map` *is* `f(a)`
21 |
22 |
23 |
--------------------------------------------------------------------------------
/src/jekyll/_posts/2014-1-5-single-threaded-applicative.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: ""
4 | published: true
5 | data:
6 | x: 650
7 | y: 1750
8 | rotate: -30
9 | z: 1500
10 | ---
11 |
12 | # SingleThreaded Monad #
13 |
14 | *flatMap* method
15 |
16 | {% highlight scala %}
17 | def flatMap[A,B](a: SingleThreaded[A],
18 | f: A => SingleThreaded[B]): SingleThreaded[B] =
19 | {% endhighlight %}
20 |
21 | * `SingleThreaded[A]` *is* `A`
22 | * `A => SingleThreaded[B]` *is* `A => B`
23 | * `flatMap` *is* `f(a)`
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/jekyll/_posts/2014-1-6-single-threaded-applicative.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: ""
4 | published: true
5 | data:
6 | x: 1550
7 | y: 650
8 | rotate: -40
9 | z: 1500
10 | ---
11 |
12 | # SingleThreaded Applicative Functor #
13 |
14 | *ap* method
15 |
16 | {% highlight scala %}
17 | def ap[A,B](
18 | a: SingleThreaded[A],
19 | f: SingleThreaded[A => B]): SingleThreaded[B] =
20 | {% endhighlight %}
21 |
22 | * `SingleThreaded[A]` *is* `A`
23 | * `SingleThreaded[A => B]` *is* `A => B`
24 | * `ap` *is* `f(a)`
25 |
26 |
27 |
--------------------------------------------------------------------------------
/src/jekyll/_posts/2014-2-1-the-test.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: ""
4 | published: true
5 | data:
6 | x: 2400
7 | y: 0
8 | rotate: -25
9 | z: 1800
10 | ---
11 |
12 | # Now a single-threaded test #
13 |
14 | {% highlight scala %}
15 | val api: GhApi[SingleThreaded] = new StubbedApi
16 | val service = new GenericStatisticsService(api)
17 | val expected = Statistics("Josh",Seq(Watcher()), Seq(PullRequest()))
18 | val results = service.statistics("Josh")
19 | results must equalTo(expected)
20 | {% endhighlight %}
--------------------------------------------------------------------------------
/src/jekyll/_posts/2015-1-1-conclussions.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: ""
4 | published: true
5 | data:
6 | x: 3350
7 | y: 350
8 | rotate: 25
9 | z: 1900
10 | ---
11 |
12 | # Conclusions #
13 |
14 | * Not your average Object Oriented design
15 | * We achieved *100% asynchronous* user code.
16 | * Our tests run *single threaded* (Note: ~2-4x faster w/ stubbed out API)
17 | * The *same code* can change *computational context*
18 | * Wealth of FP patterns to leverage
19 |
--------------------------------------------------------------------------------
/src/jekyll/_posts/2015-1-2-questions.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: ""
4 | published: true
5 | data:
6 | x: 3750
7 | y: 950
8 | rotate: 30
9 | z: 2900
10 | ---
11 |
12 | # Questions?
13 |
14 | * Slides: [http://jsuereth.com/intro-to-fp](http://jsuereth.com/intro-to-fp)
15 | * Sample Code: [http://github.com/jsuereth/intro-to-fp](http://github.com/jsuereth/intro-to-fp)
16 | * Twitter: [@jsuereth](www.twitter.com/jsuereth)
17 | * Book: [http://manning.com/suereth](http://manning.com/suereth)
--------------------------------------------------------------------------------
/src/jekyll/_posts/slide_template.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: ""
4 | published: false
5 | classes:
6 | - slide
7 | data:
8 | x: 0
9 | y: 0
10 |
11 | ---
12 |
13 |
--------------------------------------------------------------------------------
/src/jekyll/_sass/config.rb:
--------------------------------------------------------------------------------
1 | # Require any additional compass plugins here.
2 |
3 | # Set this to the root of your project when deployed:
4 | http_path = "/"
5 |
6 | # Paths to the base theme directories.
7 | css_dir = "../css"
8 | sass_dir = "../_sass"
9 | javascripts_dir = "../js"
10 | project_type = :stand_alone
11 |
12 | # Images are located in a shared library. Sprites are automatically generated.
13 | # images_dir = "docroot/sites/all/libraries/assets"
14 |
15 | # You can select your preferred output style here (can be overridden via the command line):
16 | # output_style = :expanded or :nested or :compact or :compressed
17 | output_style = :nested
18 |
19 | # To enable relative paths to assets via compass helper functions. Uncomment:
20 | relative_assets = true
21 |
22 | # To disable debugging comments that display the original location of your selectors. Uncomment:
23 | line_comments = false
24 |
25 |
26 | # If you prefer the indented syntax, you might want to regenerate this
27 | # project again passing --syntax sass, or you can uncomment this:
28 | # preferred_syntax = :sass
29 | # and then run:
30 | # sass-convert -R --from scss --to sass sass scss && rm -rf sass && mv scss sass
31 |
--------------------------------------------------------------------------------
/src/jekyll/_sass/hekyll.scss:
--------------------------------------------------------------------------------
1 | @import "partials/base";
2 |
3 | body {
4 | font-family: $myriad;
5 |
6 | min-height: 740px;
7 |
8 | background: $bg;
9 |
10 | -webkit-font-smoothing: antialiased;
11 |
12 | color: $text;
13 | }
14 |
15 | b, strong { font-weight: bold }
16 | i, em { font-style: italic}
17 |
18 | a {
19 | color: $softlight;
20 | text-decoration: underline;
21 | padding: 0 0.1em;
22 | background: rgba(lighten($bg, 15%), .5);
23 | border-radius: 0.2em;
24 |
25 | @include transition-property(background);
26 | @include transition-duration(0.5s);
27 | }
28 |
29 | a:hover {
30 | background: rgba(lighten($bg, 15%),1);
31 | }
32 |
33 | h1 {
34 | color: $highlight;
35 | font: {
36 | weight: bold;
37 | size: 2em;
38 | }
39 | }
40 |
41 | /* COMMON STEP STYLES */
42 |
43 | .step {
44 | width: 900px;
45 | padding: 40px;
46 |
47 | @include box-sizing(border-box);
48 |
49 | font-family: $myriad;
50 |
51 | font-size: 48px;
52 | line-height: 1.5;
53 | }
54 |
55 | /* fade out inactive slides */
56 |
57 | .step {
58 | @include transition-duration(1s);
59 | }
60 |
61 | .step:not(.active) {
62 | opacity: 0.3;
63 | }
64 |
65 | /* Simple Slideshow Styles */
66 |
67 | .simple-slideshow .step:not(.active) {
68 | opacity: 0;
69 | }
70 |
71 | /* overview step */
72 |
73 | #overview {
74 | z-index: -1;
75 | padding: 0;
76 | }
77 |
78 | /* on overview step everything is visible */
79 |
80 | #impress.step-overview .step {
81 | opacity: 1;
82 | cursor: pointer;
83 | }
84 |
85 | /*
86 | * SLIDE STEP STYLES
87 | *
88 | * inspired by: http://html5slides.googlecode.com/svn/trunk/styles.css
89 | *
90 | * ;)
91 | */
92 |
93 | .slide {
94 | display: block;
95 |
96 | width: 900px;
97 | height: 700px;
98 |
99 | padding: 40px 60px;
100 |
101 | border-radius: 10px;
102 |
103 | background-color: $base;
104 |
105 | box-shadow: 0 2px 6px rgba(0, 0, 0, .1);
106 | border: 1px solid rgba(0, 0, 0, .3);
107 |
108 | font-family: 'Open Sans', Arial, sans-serif;
109 |
110 | color: $text;
111 | text-shadow: 0 2px 2px rgba(0, 0, 0, .1);
112 |
113 | font-size: 30px;
114 | line-height: 36px;
115 |
116 | letter-spacing: -1px;
117 | }
118 |
119 | .slide {
120 | q {
121 | display: block;
122 | font-size: 50px;
123 | line-height: 72px;
124 |
125 | margin-top: 100px;
126 | }
127 |
128 | q strong {
129 | white-space: nowrap;
130 | }
131 |
132 | p {
133 | margin: 1.25em 0;
134 | }
135 |
136 | h1 {
137 | line-height: 100%;
138 | }
139 |
140 | ul, p, h2, h3, h4, h5, h6 {
141 | margin-top: 1em;
142 | }
143 |
144 | li {
145 | margin: 0 0 0.5em;
146 | }
147 | }
148 |
149 | /* IMPRESS NOT SUPPORTED STYLES */
150 |
151 | .fallback-message {
152 | font-family: sans-serif;
153 | line-height: 1.3;
154 |
155 | display: none;
156 | width: 780px;
157 | padding: 10px 10px 0;
158 | margin: 20px auto;
159 |
160 | border-radius: 10px;
161 | border: 1px solid #E4C652;
162 | background: #EEDC94;
163 |
164 | p {
165 | margin-bottom: 10px;
166 | }
167 | }
168 |
169 | .impress-not-supported {
170 | .step {
171 | position: relative;
172 | opacity: 1;
173 | margin: 20px auto;
174 | }
175 | .fallback-message {
176 | display: block;
177 | }
178 | }
179 |
180 | /* PRINT STYLES */
181 | @media print {
182 | .step {
183 | page-break-after: always;
184 | }
185 | }
186 |
--------------------------------------------------------------------------------
/src/jekyll/_sass/partials/_base.scss:
--------------------------------------------------------------------------------
1 | // Compass
2 | // - Install: sudo gem install compass
3 | // - Docs: http://compass-style.org/
4 | // - Source: https://github.com/chriseppstein/compass
5 |
6 | // Imports -------------------------------------------------------------------
7 | @import "compass/reset";
8 | @import "compass/utilities";
9 | @import "compass/css3";
10 |
11 | // Partials.
12 | @import "partials/variables";
13 | //@import "partials/elements";
14 |
15 | // Font Size Reference (12px base)
16 | //------------------------------------------------------------------------------
17 | // 6px | 0.5em | 50% | 5pt
18 | // 7px | 0.583em | 58.3% | 5pt
19 | // 8px | 0.667em | 66.7% | 6pt
20 | // 9px | 0.75em | 75% | 7pt
21 | // 10px | 0.833em | 83.3% | 8pt
22 | // 11px | 0.917em | 91.7% | 8pt
23 | // 12px | 1em | 100% | 9pt
24 | // 13px | 1.083em | 108.3% | 10pt
25 | // 14px | 1.167em | 116.7% | 11pt
26 | // 15px | 1.25em | 125% | 11pt
27 | // 16px | 1.333em | 133.3% | 12pt
28 | // 17px | 1.417em | 141.7% | 13pt
29 | // 18px | 1.5em | 150% | 14pt
30 | // 19px | 1.583em | 158.3% | 14pt
31 | // 20px | 1.667em | 166.7% | 15pt
32 | // 21px | 1.75em | 175% | 16pt
33 | // 22px | 1.833em | 183.3% | 17pt
34 | // 23px | 1.917em | 191.7% | 17pt
35 | // 24px | 2em | 200% | 18pt
36 |
37 | // 40px | 3.333em | 200% | 18pt // content padding
38 |
39 |
40 |
41 | // Hide elements from all users.
42 | //------------------------------------------------------------------------------
43 | // Used for elements which should not be immediately displayed to any user.
44 |
45 | .hidden {
46 | display: none !important;
47 | visibility: hidden;
48 | }
49 |
50 | // Visually hidden, but available for screen readers.
51 | //------------------------------------------------------------------------------
52 | // Used for information required for screen-reader users to understand and use
53 | // the site where visual display is undesirable. Information provided in this
54 | // manner should be kept concise, to avoid unnecessary burden on the user.
55 | // "!important" is used to prevent unintentional overrides.
56 |
57 | .invisible,
58 | .element-invisible {
59 | border: 0;
60 | clip: rect(1px 1px 1px 1px); // IE6, IE7
61 | clip: rect(1px, 1px, 1px, 1px);
62 | height: 1px;
63 | margin: -1px;
64 | overflow: hidden;
65 | padding: 0;
66 | position: absolute !important;
67 | width: 1px;
68 | }
69 |
70 | // Visually hidden, but available to screenreaders and keyboard navigation.
71 | //------------------------------------------------------------------------------
72 | // The .element-focusable class extends the .element-invisible class to allow
73 | // the element to be focusable when navigated to via the keyboard. This is
74 | // typically used for skip links.
75 |
76 | .invisible.focusable:active,
77 | .invisible.focusable:focus,
78 | .element-invisible.element-focusable:active,
79 | .element-invisible.element-focusable:focus {
80 | clip: auto;
81 | height: auto;
82 | margin: 0;
83 | overflow: visible;
84 | position: static !important;
85 | width: auto;
86 | }
87 |
--------------------------------------------------------------------------------
/src/jekyll/_sass/partials/_elements.scss:
--------------------------------------------------------------------------------
1 | /*! Adapted from: normalize.css 2011-09-22T17:42 UTC - http://github.com/necolas/normalize.css */
2 |
3 | // HTML5
4 | //------------------------------------------------------------------------------
5 |
6 | // Corrects block display not defined in IE6/7/8/9 & FF3.
7 | @include reset-html5;
8 |
9 | // Corrects inline-block display not defined in IE6/7/8/9 & FF3.
10 | audio,
11 | canvas,
12 | video {
13 | display: inline-block;
14 | *display: inline;
15 | *zoom: 1;
16 | }
17 |
18 | // Prevents modern browsers from displaying 'audio' without controls.
19 | audio:not([controls]) {
20 | display: none;
21 | }
22 |
23 | // Addresses styling for 'hidden' attribute not present in IE7/8/9, FF3, S4
24 | [hidden] {
25 | display: none;
26 | }
27 |
28 |
29 | // Base
30 | //------------------------------------------------------------------------------
31 |
32 | html {
33 | margin: 0;
34 | padding: 0;
35 | // Corrects text resizing oddly in IE6/7 when body font-size is set using em
36 | // units. http://clagnut.com/blog/348/#c790
37 | font-size: 100%;
38 | // Keeps page centred in all browsers regardless of content height.
39 | overflow-y: scroll;
40 | // Prevents iOS text size adjust after orientation change, without disabling
41 | // user zoom. http://www.456bereastreet.com/archive/201012/
42 | // -webkit-text-size-adjust: 100%;
43 | // -ms-text-size-adjust: 100%;
44 | }
45 |
46 | body {
47 | font-family: $sans;
48 | color: #7d7d7d;
49 | font-size: 75%; // 12px
50 | line-height: 1.5;
51 | padding: 0;
52 | // Addresses margins handled incorrectly in IE6/7.
53 | margin: 0;
54 | }
55 |
56 | .clear-block,
57 | .clearfix {
58 | @include bp-clearfix();
59 | }
60 |
61 | .float-right {
62 | @include float(right);
63 | }
64 | .float-left {
65 | @include float(left);
66 | }
67 |
68 | // Links
69 | //------------------------------------------------------------------------------
70 |
71 | a {
72 | text-decoration: none;
73 | outline: none;
74 | @include link-colors($link, $link, $link);
75 | &:focus {
76 | // Addresses outline displayed oddly in Chrome.
77 | outline: thin dotted;
78 | }
79 | &:hover,
80 | &:active {
81 | text-decoration: underline;
82 | @include link-colors($link-hover, $link-hover, $link-hover);
83 | // Improves readability when focused and also mouse hovered in all browsers.
84 | // http://people.opera.com/patrickl/experiments/keyboard/test
85 | outline: 0;
86 | }
87 | }
88 |
89 |
90 | // Typography
91 | //------------------------------------------------------------------------------
92 |
93 | p {
94 | line-height: 1.5;
95 | margin: 20px 0;
96 | &:first-child {
97 | margin-top: 0;
98 | }
99 | }
100 |
101 | #{headings()} {
102 | font-weight: 400;
103 | line-height: 1;
104 | margin: 0 0 0.833em 0;
105 | padding: 0;
106 | }
107 |
108 | h1 {
109 | font-size: 3em;
110 | line-height: 1;
111 | margin-bottom: 10px;
112 | }
113 | h2 {
114 | font-size: 2em;
115 | margin-bottom: 10px;
116 | }
117 | h3 {
118 | font-size: 1.5em;
119 | line-height: 1;
120 | margin-bottom: 10px;
121 | }
122 | h4 {
123 | font-size: 1.2em;
124 | line-height: 1.25;
125 | margin-bottom: 10px;
126 | }
127 | h5 {
128 | font-size: 1em;
129 | font-weight: bold;
130 | margin-bottom: 10px;
131 | }
132 | h6 {
133 | font-size: 1em;
134 | font-weight: bold;
135 | }
136 |
137 | h2#page-title {
138 | margin: 1em 1em 0 1em;
139 | }
140 | abbr[title] {
141 | // Addresses styling not present in IE7/8/9, S5, Chrome.
142 | border-bottom: 1px dotted;
143 | }
144 |
145 | b,
146 | strong {
147 | // Addresses style set to 'bolder' in FF3/4, S4/5, Chrome.
148 | font-weight: bold;
149 | }
150 |
151 | blockquote {
152 | margin: 1em 40px;
153 | &:first-child {
154 | margin-top: 0;
155 | }
156 | }
157 |
158 | dfn {
159 | // Addresses styling not present in S5, Chrome.
160 | font-style: italic;
161 | }
162 |
163 | mark {
164 | // Addresses styling not present in IE6/7/8/9.
165 | background: #ff0;
166 | color: #000;
167 | }
168 |
169 | pre,
170 | code,
171 | kbd,
172 | samp {
173 | // Corrects font family set oddly in IE6, S4/5, Chrome.
174 | // http://en.wikipedia.org/wiki/User:Davidgothberg/Test59
175 | font-family: monospace, serif;
176 | _font-family: "courier new", monospace;
177 | font-size: 1em;
178 | }
179 |
180 | pre,
181 | .codeblock {
182 | background-color: #f5f5f5;
183 | border: solid 1px #ddd;
184 | padding: 1em;
185 | @include border-radius(4px);
186 | // Improves readability of pre-formatted text in all browsers.
187 | white-space: pre;
188 | white-space: pre-wrap;
189 | word-wrap: break-word;
190 | }
191 |
192 | q {
193 | // Addresses CSS quotes not supported in IE6/7.
194 | quotes: none;
195 | &:before,
196 | &:after {
197 | // Addresses quote property not supported in S4.
198 | content: '';
199 | content: none;
200 | }
201 | }
202 |
203 | small {
204 | font-size: 75%;
205 | }
206 |
207 | // Prevents sub and sup affecting line-height in all browsers.
208 | // http://gist.github.com/413930
209 | sub,
210 | sup {
211 | font-size: 75%;
212 | line-height: 0;
213 | position: relative;
214 | vertical-align: baseline;
215 | }
216 |
217 | sup {
218 | top: -0.5em;
219 | }
220 |
221 | sub {
222 | bottom: -0.25em;
223 | }
224 |
225 | // Lists
226 | //------------------------------------------------------------------------------
227 |
228 | /*ul,
229 | ol {
230 | list-style: none;
231 | margin: 0;
232 | padding: 0;
233 | }*/
234 |
235 | dl {
236 | margin: 1em 0;
237 | &:first-child {
238 | margin-top: 0;
239 | }
240 | &:only-child {
241 | margin: 0;
242 | }
243 | }
244 | dt {
245 | font-weight: bold;
246 | }
247 | dd {
248 | margin: 0 0 1em 1em;
249 | }
250 |
251 |
252 | // Embedded content
253 | //------------------------------------------------------------------------------
254 |
255 | img {
256 | // Removes border when inside 'a' element in IE6/7/8/9, FF3.
257 | border: 0;
258 | // Improves image quality when scaled in IE7.
259 | // code.flickr.com/blog/2008/11/12/on-ui-quality-the-little-things-client-side-image-resizing/
260 | -ms-interpolation-mode: bicubic;
261 | }
262 | svg:not(:root) {
263 | // Corrects overflow displayed oddly in IE9.
264 | overflow: hidden;
265 | }
266 |
267 |
268 | // Figures
269 | //------------------------------------------------------------------------------
270 |
271 | figure {
272 | // Addresses margin not present in IE6/7/8/9, S5, O11.
273 | margin: 0;
274 | }
275 |
276 |
277 | // Tables
278 | //------------------------------------------------------------------------------
279 |
280 | table {
281 | // Remove most spacing between table cells.
282 | border-collapse: collapse;
283 | border-spacing: 0;
284 | width: 100%;
285 | }
286 | td, th {
287 | padding: 6px;
288 | vertical-align: middle;
289 | }
290 | th {
291 | font-weight: bold;
292 | text-transform: uppercase;
293 | text-align: left;
294 | border-bottom: #000 solid 2px;
295 | &.field-label {
296 | background: #e5e5e5;
297 | border-bottom: none;
298 | label {
299 | padding-left: .5em;
300 | }
301 | }
302 | }
303 |
304 | table.field-multiple-table {
305 | border: #e5e5e5 solid 1px;
306 | }
307 |
308 | tr.even,
309 | tr.odd {
310 | border-width: 0 1px 0 1px;
311 | border-style: solid;
312 | border-color: #e5e5e5;
313 | background: #f2f2f2;
314 | }
315 | tr.odd {
316 | background: #fff;
317 | }
318 | tr.drag {
319 | background: #fe7;
320 | }
321 | tr.drag-previous {
322 | background: #ffb;
323 | }
324 |
325 |
326 |
327 |
--------------------------------------------------------------------------------
/src/jekyll/_sass/partials/_variables.scss:
--------------------------------------------------------------------------------
1 | // Variables
2 | //------------------------------------------------------------------------------
3 |
4 | // Colors
5 | $text: #787A64;
6 | $bg: #C5C7B6;
7 | $base: #FFFFFF;
8 | $softlight: #C0B6C7;
9 | $highlight: #6C577A;
10 |
11 |
12 | // Font Stacks
13 | //------------------------------------------------------------------------------
14 |
15 | $myriad: "Myriad Pro", Myriad, Arial, "Helvetica", Helvetica, Geneva, sans-serif;
16 | $sans: "Myriad Pro", Myriad, Arial, "Helvetica", Helvetica, Geneva, sans-serif;
17 | $serif: "Georgia", serif;
18 | $mono: Monaco, monospace, sans-serif;
19 |
20 | // Grays
21 | //------------------------------------------------------------------------------
22 | $black: #000;
23 | $grayDark: lighten($black, 25%);
24 | $gray: lighten($black, 50%);
25 | $grayLight: lighten($black, 75%);
26 | $grayLighter: lighten($black, 90%);
27 | $white: #fff;
28 |
--------------------------------------------------------------------------------
/src/jekyll/cover.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsuereth/intro-to-fp/5feab100c06a4feb3af2b9e675c6217e6fb5764a/src/jekyll/cover.png
--------------------------------------------------------------------------------
/src/jekyll/css/animations.css:
--------------------------------------------------------------------------------
1 | .slide .reveal {
2 | display: block;
3 | -webkit-transition: 0.5s;
4 | -moz-transition: 0.5s;
5 | -ms-transition: 0.5s;
6 | -o-transition: 0.5s;
7 | transition: 0.5s;
8 | }
9 | .future .reveal {
10 | display: none;
11 | }
12 | .bignerd {
13 | display: inline-block;
14 | }
15 | .present .bignerd {
16 | -webkit-transform: scale(1.5) translateX(15px) rotate(10deg);
17 | -moz-transform: scale(1.5) translateX(15px) rotate(10deg);
18 | -ms-transform: scale(1,5) translateX(15px) rotate(10deg);
19 | -o-transform: scale(1.5) translateX(15px) rotate(10deg);
20 | transform: scale(1.5) translateX(15px) rotate(10deg);
21 | }
22 |
23 | .transition-05 {
24 | -webkit-transition: 0.5s;
25 | -moz-transition: 0.5s;
26 | -ms-transition: 0.5s;
27 | -o-transition: 0.5s;
28 | transition: 0.5s;
29 | }
30 |
31 | .global-delay-1 {
32 | -webkit-transition-delay: 1.0s;
33 | -moz-transition-delay: 1.0s;
34 | -ms-transition-delay: 1.0s;
35 | -o-transition-delay: 1.0s;
36 | transition-delay: 1.0s;
37 | }
38 |
39 | .present .delay-1 {
40 | -webkit-transition-delay: 1.0s;
41 | -moz-transition-delay: 1.0s;
42 | -ms-transition-delay: 1.0s;
43 | -o-transition-delay: 1.0s;
44 | transition-delay: 1.0s;
45 | }
46 |
47 | .present .delay-5 {
48 | -webkit-transition-delay: 5.0s;
49 | -moz-transition-delay: 5.0s;
50 | -ms-transition-delay: 5.0s;
51 | -o-transition-delay: 5.0s;
52 | transition-delay: 5.0s;
53 | }
54 |
55 | .present .delay-10 {
56 | -webkit-transition-delay: 10.0s;
57 | -moz-transition-delay: 10.0s;
58 | -ms-transition-delay: 10.0s;
59 | -o-transition-delay: 10.0s;
60 | transition-delay: 10.0s;
61 | }
--------------------------------------------------------------------------------
/src/jekyll/css/custom.css:
--------------------------------------------------------------------------------
1 |
2 | /* My additions */
3 |
4 | .right-hover {
5 | position: absolute;
6 | right: 2em;
7 | top: 2em;
8 | }
9 |
10 | .slide em {
11 | font-style: normal;
12 | color: red;
13 | }
14 |
15 | .highlight pre {
16 | background: #F8F8F8;
17 | margin-top: 1em;
18 | margin-bottom: 1em;
19 | padding: 1em;
20 | border: 1px solid #C8C8C8;
21 | -webkit-border-radius: 10px; -moz-border-radius: 10px; border-radius: 10px;
22 | font-size: 22px;
23 | }
24 |
25 | .slide ol {
26 | list-style-type: decimal;
27 | display: block;
28 | }
29 |
30 | .slide ul {
31 | list-style-type: disc;
32 | display: block;
33 | }
34 |
35 | .slide li {
36 | display: list-item;
37 | }
38 |
39 | .scala .nc {
40 | font-weight: normal;
41 | color: inherit;
42 | }
43 |
44 | .scala .kt {
45 | color: rgb(17,85,204);
46 | }
47 | .scala .k, .scala .o {
48 | color: #626;
49 | font-weight: bold;
50 | }
51 |
52 | .scala {
53 | text-shadow: none;
54 | color: rgb(0,0,0);
55 | }
--------------------------------------------------------------------------------
/src/jekyll/css/fonts/roboto-regular-webfont.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsuereth/intro-to-fp/5feab100c06a4feb3af2b9e675c6217e6fb5764a/src/jekyll/css/fonts/roboto-regular-webfont.eot
--------------------------------------------------------------------------------
/src/jekyll/css/fonts/roboto-regular-webfont.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsuereth/intro-to-fp/5feab100c06a4feb3af2b9e675c6217e6fb5764a/src/jekyll/css/fonts/roboto-regular-webfont.ttf
--------------------------------------------------------------------------------
/src/jekyll/css/fonts/roboto-regular-webfont.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsuereth/intro-to-fp/5feab100c06a4feb3af2b9e675c6217e6fb5764a/src/jekyll/css/fonts/roboto-regular-webfont.woff
--------------------------------------------------------------------------------
/src/jekyll/css/fonts/roboto.css:
--------------------------------------------------------------------------------
1 | @font-face {
2 | font-family: 'RobotoRegular';
3 | src: url('roboto-regular-webfont.eot');
4 | src: url('roboto-regular-webfont.eot?#iefix') format('embedded-opentype'), url('roboto-regular-webfont.woff') format('woff'), url('roboto-regular-webfont.ttf') format('truetype'), url('roboto-regular-webfont.svg#RobotoRegular') format('svg');
5 | font-weight: normal;
6 | font-style: normal;
7 | }
--------------------------------------------------------------------------------
/src/jekyll/css/hekyll.css:
--------------------------------------------------------------------------------
1 | html, body, div, span, applet, object, iframe,
2 | h1, h2, h3, h4, h5, h6, p, blockquote, pre,
3 | a, abbr, acronym, address, big, cite, code,
4 | del, dfn, em, img, ins, kbd, q, s, samp,
5 | small, strike, strong, sub, sup, tt, var,
6 | b, u, i, center,
7 | dl, dt, dd,
8 | fieldset, form, label, legend,
9 | table, caption, tbody, tfoot, thead, tr, th, td,
10 | article, aside, canvas, details, embed,
11 | figure, figcaption, footer, header, hgroup,
12 | menu, nav, output, ruby, section, summary,
13 | time, mark, audio, video {
14 | margin: 0;
15 | padding: 0;
16 | border: 0;
17 | font-size: 100%;
18 | font: inherit;
19 | vertical-align: baseline; }
20 |
21 | body {
22 | line-height: 1; }
23 |
24 | ol, ul {
25 | list-style: none; }
26 |
27 | table {
28 | border-collapse: collapse;
29 | border-spacing: 0; }
30 |
31 | caption, th, td {
32 | text-align: left;
33 | font-weight: normal;
34 | vertical-align: middle; }
35 |
36 | q, blockquote {
37 | quotes: none; }
38 | q:before, q:after, blockquote:before, blockquote:after {
39 | content: "";
40 | content: none; }
41 |
42 | a img {
43 | border: none; }
44 |
45 | article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section, summary {
46 | display: block; }
47 |
48 | .hidden {
49 | display: none !important;
50 | visibility: hidden; }
51 |
52 | .invisible,
53 | .element-invisible {
54 | border: 0;
55 | clip: rect(1px 1px 1px 1px);
56 | clip: rect(1px, 1px, 1px, 1px);
57 | height: 1px;
58 | margin: -1px;
59 | overflow: hidden;
60 | padding: 0;
61 | position: absolute !important;
62 | width: 1px; }
63 |
64 | .invisible.focusable:active,
65 | .invisible.focusable:focus,
66 | .element-invisible.element-focusable:active,
67 | .element-invisible.element-focusable:focus {
68 | clip: auto;
69 | height: auto;
70 | margin: 0;
71 | overflow: visible;
72 | position: static !important;
73 | width: auto; }
74 |
75 | body {
76 | font-family: "RobotoRegular", "Myriad Pro", Myriad, Arial, "Helvetica", Helvetica, Geneva, sans-serif;
77 | min-height: 740px;
78 | background: #c5c7b6;
79 | -webkit-font-smoothing: antialiased;
80 | color: #787a64; }
81 |
82 | b, strong {
83 | font-weight: bold; }
84 |
85 | i, em {
86 | font-style: italic; }
87 |
88 | a {
89 | color: #c0b6c7;
90 | text-decoration: underline;
91 | padding: 0 0.1em;
92 | background: rgba(231, 232, 225, 0.5);
93 | border-radius: 0.2em;
94 | -moz-transition-property: background;
95 | -webkit-transition-property: background;
96 | -o-transition-property: background;
97 | transition-property: background;
98 | -moz-transition-duration: 0.5s;
99 | -webkit-transition-duration: 0.5s;
100 | -o-transition-duration: 0.5s;
101 | transition-duration: 0.5s; }
102 |
103 | a:hover {
104 | background: #e7e8e1; }
105 |
106 | h1 {
107 | color: #6c577a;
108 | font-weight: bold;
109 | font-size: 2em; }
110 |
111 | /* COMMON STEP STYLES */
112 | .step {
113 | width: 900px;
114 | padding: 40px;
115 | -moz-box-sizing: border-box;
116 | -webkit-box-sizing: border-box;
117 | -ms-box-sizing: border-box;
118 | box-sizing: border-box;
119 | font-family: "RobotoRegular", "Myriad Pro", Myriad, Arial, "Helvetica", Helvetica, Geneva, sans-serif;
120 | font-size: 48px;
121 | line-height: 1.5; }
122 |
123 | /* fade out inactive slides */
124 | .step {
125 | -moz-transition-duration: 1s;
126 | -webkit-transition-duration: 1s;
127 | -o-transition-duration: 1s;
128 | transition-duration: 1s; }
129 |
130 | .step:not(.active) {
131 | opacity: 0.3; }
132 |
133 | /* Simple Slideshow Styles */
134 | .simple-slideshow .step:not(.active) {
135 | opacity: 0; }
136 |
137 | /* overview step */
138 | #overview {
139 | z-index: -1;
140 | padding: 0; }
141 |
142 | /* on overview step everything is visible */
143 | #impress.step-overview .step {
144 | opacity: 1;
145 | cursor: pointer; }
146 |
147 | /*
148 | * SLIDE STEP STYLES
149 | *
150 | * inspired by: http://html5slides.googlecode.com/svn/trunk/styles.css
151 | *
152 | * ;)
153 | */
154 | .slide {
155 | display: block;
156 | width: 900px;
157 | height: 700px;
158 | padding: 40px 60px;
159 | border-radius: 10px;
160 | background-color: white;
161 | box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
162 | border: 1px solid rgba(0, 0, 0, 0.3);
163 | font-family: "RobotoRegular", 'Open Sans', Arial, sans-serif;
164 | color: #787a64;
165 | text-shadow: 0 2px 2px rgba(0, 0, 0, 0.1);
166 | font-size: 30px;
167 | line-height: 36px;
168 | letter-spacing: -1px; }
169 |
170 | .slide q {
171 | display: block;
172 | font-size: 50px;
173 | line-height: 72px;
174 | margin-top: 100px; }
175 | .slide q strong {
176 | white-space: nowrap; }
177 | .slide p {
178 | margin: 1.25em 0; }
179 | .slide h1 {
180 | line-height: 100%; }
181 | .slide ul, .slide p, .slide h2, .slide h3, .slide h4, .slide h5, .slide h6 {
182 | margin-top: 1em; }
183 | .slide li {
184 | margin: 0 0 0.5em; }
185 |
186 | /* IMPRESS NOT SUPPORTED STYLES */
187 | .fallback-message {
188 | font-family: sans-serif;
189 | line-height: 1.3;
190 | display: none;
191 | width: 780px;
192 | padding: 10px 10px 0;
193 | margin: 20px auto;
194 | border-radius: 10px;
195 | border: 1px solid #E4C652;
196 | background: #EEDC94; }
197 | .fallback-message p {
198 | margin-bottom: 10px; }
199 |
200 | .impress-not-supported .step {
201 | position: relative;
202 | opacity: 1;
203 | margin: 20px auto; }
204 | .impress-not-supported .fallback-message {
205 | display: block; }
206 |
207 | /* PRINT STYLES */
208 | @media print {
209 | .step {
210 | page-break-after: always; } }
211 |
--------------------------------------------------------------------------------
/src/jekyll/css/syntax.css:
--------------------------------------------------------------------------------
1 | .hll { background-color: #ffffcc }
2 | .scala { background: #f8f8f8; }
3 | .c { color: #408080; font-style: italic } /* Comment */
4 | .err { border: 1px solid #FF0000 } /* Error */
5 | .k { color: #008000; font-weight: bold } /* Keyword */
6 | .o { color: #666666 } /* Operator */
7 | .cm { color: #408080; font-style: italic } /* Comment.Multiline */
8 | .cp { color: #BC7A00 } /* Comment.Preproc */
9 | .c1 { color: #408080; font-style: italic } /* Comment.Single */
10 | .cs { color: #408080; font-style: italic } /* Comment.Special */
11 | .gd { color: #A00000 } /* Generic.Deleted */
12 | .ge { font-style: italic } /* Generic.Emph */
13 | .gr { color: #FF0000 } /* Generic.Error */
14 | .gh { color: #000080; font-weight: bold } /* Generic.Heading */
15 | .gi { color: #00A000 } /* Generic.Inserted */
16 | .go { color: #808080 } /* Generic.Output */
17 | .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
18 | .gs { font-weight: bold } /* Generic.Strong */
19 | .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
20 | .gt { color: #0040D0 } /* Generic.Traceback */
21 | .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
22 | .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
23 | .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
24 | .kp { color: #008000 } /* Keyword.Pseudo */
25 | .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
26 | .kt { color: #B00040 } /* Keyword.Type */
27 | .m { color: #666666 } /* Literal.Number */
28 | .s { color: #BA2121 } /* Literal.String */
29 | .na { color: #7D9029 } /* Name.Attribute */
30 | .nb { color: #008000 } /* Name.Builtin */
31 | .nc { color: #0000FF; font-weight: bold } /* Name.Class */
32 | .no { color: #880000 } /* Name.Constant */
33 | .nd { color: #AA22FF } /* Name.Decorator */
34 | .ni { color: #999999; font-weight: bold } /* Name.Entity */
35 | .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
36 | .nf { color: #0000FF } /* Name.Function */
37 | .nl { color: #A0A000 } /* Name.Label */
38 | .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
39 | .nt { color: #008000; font-weight: bold } /* Name.Tag */
40 | .nv { color: #19177C } /* Name.Variable */
41 | .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
42 | .w { color: #bbbbbb } /* Text.Whitespace */
43 | .mf { color: #666666 } /* Literal.Number.Float */
44 | .mh { color: #666666 } /* Literal.Number.Hex */
45 | .mi { color: #666666 } /* Literal.Number.Integer */
46 | .mo { color: #666666 } /* Literal.Number.Oct */
47 | .sb { color: #BA2121 } /* Literal.String.Backtick */
48 | .sc { color: #BA2121 } /* Literal.String.Char */
49 | .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */
50 | .s2 { color: #BA2121 } /* Literal.String.Double */
51 | .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
52 | .sh { color: #BA2121 } /* Literal.String.Heredoc */
53 | .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
54 | .sx { color: #008000 } /* Literal.String.Other */
55 | .sr { color: #BB6688 } /* Literal.String.Regex */
56 | .s1 { color: #BA2121 } /* Literal.String.Single */
57 | .ss { color: #19177C } /* Literal.String.Symbol */
58 | .bp { color: #008000 } /* Name.Builtin.Pseudo */
59 | .vc { color: #19177C } /* Name.Variable.Class */
60 | .vg { color: #19177C } /* Name.Variable.Global */
61 | .vi { color: #19177C } /* Name.Variable.Instance */
62 | .il { color: #666666 } /* Literal.Number.Integer.Long */
63 |
64 |
65 | .scala .hll { background-color: #ffffcc }
66 | .scala { background: #f8f8f8; }
67 | .scala .c { color: #408080; font-style: italic } /* Comment */
68 | .scala .err { border: 1px solid #FF0000 } /* Error */
69 | .scala .k { color: #008000; font-weight: bold } /* Keyword */
70 | .scala .o { color: #666666 } /* Operator */
71 | .scala .cm { color: #408080; font-style: italic } /* Comment.Multiline */
72 | .scala .cp { color: #BC7A00 } /* Comment.Preproc */
73 | .scala .c1 { color: #408080; font-style: italic } /* Comment.Single */
74 | .scala .cs { color: #408080; font-style: italic } /* Comment.Special */
75 | .scala .gd { color: #A00000 } /* Generic.Deleted */
76 | .scala .ge { font-style: italic } /* Generic.Emph */
77 | .scala .gr { color: #FF0000 } /* Generic.Error */
78 | .scala .gh { color: #000080; font-weight: bold } /* Generic.Heading */
79 | .scala .gi { color: #00A000 } /* Generic.Inserted */
80 | .scala .go { color: #808080 } /* Generic.Output */
81 | .scala .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
82 | .scala .gs { font-weight: bold } /* Generic.Strong */
83 | .scala .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
84 | .scala .gt { color: #0040D0 } /* Generic.Traceback */
85 | .scala .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
86 | .scala .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
87 | .scala .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
88 | .scala .kp { color: #008000 } /* Keyword.Pseudo */
89 | .scala .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
90 | .scala .kt { color: #B00040 } /* Keyword.Type */
91 | .scala .m { color: #666666 } /* Literal.Number */
92 | .scala .s { color: #BA2121 } /* Literal.String */
93 | .scala .na { color: #7D9029 } /* Name.Attribute */
94 | .scala .nb { color: #008000 } /* Name.Builtin */
95 | .scala .nc { color: #0000FF; font-weight: bold } /* Name.Class */
96 | .scala .no { color: #880000 } /* Name.Constant */
97 | .scala .nd { color: #AA22FF } /* Name.Decorator */
98 | .scala .ni { color: #999999; font-weight: bold } /* Name.Entity */
99 | .scala .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
100 | .scala .nf { color: #0000FF } /* Name.Function */
101 | .scala .nl { color: #A0A000 } /* Name.Label */
102 | .scala .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
103 | .scala .nt { color: #008000; font-weight: bold } /* Name.Tag */
104 | .scala .nv { color: #19177C } /* Name.Variable */
105 | .scala .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
106 | .scala .w { color: #bbbbbb } /* Text.Whitespace */
107 | .scala .mf { color: #666666 } /* Literal.Number.Float */
108 | .scala .mh { color: #666666 } /* Literal.Number.Hex */
109 | .scala .mi { color: #666666 } /* Literal.Number.Integer */
110 | .scala .mo { color: #666666 } /* Literal.Number.Oct */
111 | .scala .sb { color: #BA2121 } /* Literal.String.Backtick */
112 | .scala .sc { color: #BA2121 } /* Literal.String.Char */
113 | .scala .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */
114 | .scala .s2 { color: #BA2121 } /* Literal.String.Double */
115 | .scala .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
116 | .scala .sh { color: #BA2121 } /* Literal.String.Heredoc */
117 | .scala .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
118 | .scala .sx { color: #008000 } /* Literal.String.Other */
119 | .scala .sr { color: #BB6688 } /* Literal.String.Regex */
120 | .scala .s1 { color: #BA2121 } /* Literal.String.Single */
121 | .scala .ss { color: #19177C } /* Literal.String.Symbol */
122 | .scala .bp { color: #008000 } /* Name.Builtin.Pseudo */
123 | .scala .vc { color: #19177C } /* Name.Variable.Class */
124 | .scala .vg { color: #19177C } /* Name.Variable.Global */
125 | .scala .vi { color: #19177C } /* Name.Variable.Instance */
126 | .scala .il { color: #666666 } /* Literal.Number.Integer.Long */
127 |
--------------------------------------------------------------------------------
/src/jekyll/impress.js:
--------------------------------------------------------------------------------
1 | /**
2 | * impress.js
3 | *
4 | * impress.js is a presentation tool based on the power of CSS3 transforms and transitions
5 | * in modern browsers and inspired by the idea behind prezi.com.
6 | *
7 | *
8 | * Copyright 2011-2012 Bartek Szopka (@bartaz)
9 | *
10 | * Released under the MIT and GPL Licenses.
11 | *
12 | * ------------------------------------------------
13 | * author: Bartek Szopka
14 | * version: 0.5.3
15 | * url: http://bartaz.github.com/impress.js/
16 | * source: http://github.com/bartaz/impress.js/
17 | */
18 |
19 | /*jshint bitwise:true, curly:true, eqeqeq:true, forin:true, latedef:true, newcap:true,
20 | noarg:true, noempty:true, undef:true, strict:true, browser:true */
21 |
22 | // You are one of those who like to know how thing work inside?
23 | // Let me show you the cogs that make impress.js run...
24 | (function ( document, window ) {
25 | 'use strict';
26 |
27 | // HELPER FUNCTIONS
28 |
29 | // `pfx` is a function that takes a standard CSS property name as a parameter
30 | // and returns it's prefixed version valid for current browser it runs in.
31 | // The code is heavily inspired by Modernizr http://www.modernizr.com/
32 | var pfx = (function () {
33 |
34 | var style = document.createElement('dummy').style,
35 | prefixes = 'Webkit Moz O ms Khtml'.split(' '),
36 | memory = {};
37 |
38 | return function ( prop ) {
39 | if ( typeof memory[ prop ] === "undefined" ) {
40 |
41 | var ucProp = prop.charAt(0).toUpperCase() + prop.substr(1),
42 | props = (prop + ' ' + prefixes.join(ucProp + ' ') + ucProp).split(' ');
43 |
44 | memory[ prop ] = null;
45 | for ( var i in props ) {
46 | if ( style[ props[i] ] !== undefined ) {
47 | memory[ prop ] = props[i];
48 | break;
49 | }
50 | }
51 |
52 | }
53 |
54 | return memory[ prop ];
55 | };
56 |
57 | })();
58 |
59 | // `arraify` takes an array-like object and turns it into real Array
60 | // to make all the Array.prototype goodness available.
61 | var arrayify = function ( a ) {
62 | return [].slice.call( a );
63 | };
64 |
65 | // `css` function applies the styles given in `props` object to the element
66 | // given as `el`. It runs all property names through `pfx` function to make
67 | // sure proper prefixed version of the property is used.
68 | var css = function ( el, props ) {
69 | var key, pkey;
70 | for ( key in props ) {
71 | if ( props.hasOwnProperty(key) ) {
72 | pkey = pfx(key);
73 | if ( pkey !== null ) {
74 | el.style[pkey] = props[key];
75 | }
76 | }
77 | }
78 | return el;
79 | };
80 |
81 | // `toNumber` takes a value given as `numeric` parameter and tries to turn
82 | // it into a number. If it is not possible it returns 0 (or other value
83 | // given as `fallback`).
84 | var toNumber = function (numeric, fallback) {
85 | return isNaN(numeric) ? (fallback || 0) : Number(numeric);
86 | };
87 |
88 | // `byId` returns element with given `id` - you probably have guessed that ;)
89 | var byId = function ( id ) {
90 | return document.getElementById(id);
91 | };
92 |
93 | // `$` returns first element for given CSS `selector` in the `context` of
94 | // the given element or whole document.
95 | var $ = function ( selector, context ) {
96 | context = context || document;
97 | return context.querySelector(selector);
98 | };
99 |
100 | // `$$` return an array of elements for given CSS `selector` in the `context` of
101 | // the given element or whole document.
102 | var $$ = function ( selector, context ) {
103 | context = context || document;
104 | return arrayify( context.querySelectorAll(selector) );
105 | };
106 |
107 | // `triggerEvent` builds a custom DOM event with given `eventName` and `detail` data
108 | // and triggers it on element given as `el`.
109 | var triggerEvent = function (el, eventName, detail) {
110 | var event = document.createEvent("CustomEvent");
111 | event.initCustomEvent(eventName, true, true, detail);
112 | el.dispatchEvent(event);
113 | };
114 |
115 | // `translate` builds a translate transform string for given data.
116 | var translate = function ( t ) {
117 | return " translate3d(" + t.x + "px," + t.y + "px," + t.z + "px) ";
118 | };
119 |
120 | // `rotate` builds a rotate transform string for given data.
121 | // By default the rotations are in X Y Z order that can be reverted by passing `true`
122 | // as second parameter.
123 | var rotate = function ( r, revert ) {
124 | var rX = " rotateX(" + r.x + "deg) ",
125 | rY = " rotateY(" + r.y + "deg) ",
126 | rZ = " rotateZ(" + r.z + "deg) ";
127 |
128 | return revert ? rZ+rY+rX : rX+rY+rZ;
129 | };
130 |
131 | // `scale` builds a scale transform string for given data.
132 | var scale = function ( s ) {
133 | return " scale(" + s + ") ";
134 | };
135 |
136 | // `perspective` builds a perspective transform string for given data.
137 | var perspective = function ( p ) {
138 | return " perspective(" + p + "px) ";
139 | };
140 |
141 | // `getElementFromHash` returns an element located by id from hash part of
142 | // window location.
143 | var getElementFromHash = function () {
144 | // get id from url # by removing `#` or `#/` from the beginning,
145 | // so both "fallback" `#slide-id` and "enhanced" `#/slide-id` will work
146 | return byId( window.location.hash.replace(/^#\/?/,"") );
147 | };
148 |
149 | // `computeWindowScale` counts the scale factor between window size and size
150 | // defined for the presentation in the config.
151 | var computeWindowScale = function ( config ) {
152 | var hScale = window.innerHeight / config.height,
153 | wScale = window.innerWidth / config.width,
154 | scale = hScale > wScale ? wScale : hScale;
155 |
156 | if (config.maxScale && scale > config.maxScale) {
157 | scale = config.maxScale;
158 | }
159 |
160 | if (config.minScale && scale < config.minScale) {
161 | scale = config.minScale;
162 | }
163 |
164 | return scale;
165 | };
166 |
167 | // CHECK SUPPORT
168 | var body = document.body;
169 |
170 | var ua = navigator.userAgent.toLowerCase();
171 | var impressSupported =
172 | // browser should support CSS 3D transtorms
173 | ( pfx("perspective") !== null ) &&
174 |
175 | // and `classList` and `dataset` APIs
176 | ( body.classList ) &&
177 | ( body.dataset ) &&
178 |
179 | // but some mobile devices need to be blacklisted,
180 | // because their CSS 3D support or hardware is not
181 | // good enough to run impress.js properly, sorry...
182 | ( ua.search(/(iphone)|(ipod)|(android)/) === -1 );
183 |
184 | if (!impressSupported) {
185 | // we can't be sure that `classList` is supported
186 | body.className += " impress-not-supported ";
187 | } else {
188 | body.classList.remove("impress-not-supported");
189 | body.classList.add("impress-supported");
190 | }
191 |
192 | // GLOBALS AND DEFAULTS
193 |
194 | // This is were the root elements of all impress.js instances will be kept.
195 | // Yes, this means you can have more than one instance on a page, but I'm not
196 | // sure if it makes any sense in practice ;)
197 | var roots = {};
198 |
199 | // some default config values.
200 | var defaults = {
201 | width: 1024,
202 | height: 768,
203 | maxScale: 1,
204 | minScale: 0,
205 |
206 | perspective: 1000,
207 |
208 | transitionDuration: 1000
209 | };
210 |
211 | // it's just an empty function ... and a useless comment.
212 | var empty = function () { return false; };
213 |
214 | // IMPRESS.JS API
215 |
216 | // And that's where interesting things will start to happen.
217 | // It's the core `impress` function that returns the impress.js API
218 | // for a presentation based on the element with given id ('impress'
219 | // by default).
220 | var impress = window.impress = function ( rootId ) {
221 |
222 | // If impress.js is not supported by the browser return a dummy API
223 | // it may not be a perfect solution but we return early and avoid
224 | // running code that may use features not implemented in the browser.
225 | if (!impressSupported) {
226 | return {
227 | init: empty,
228 | goto: empty,
229 | prev: empty,
230 | next: empty
231 | };
232 | }
233 |
234 | rootId = rootId || "impress";
235 |
236 | // if given root is already initialized just return the API
237 | if (roots["impress-root-" + rootId]) {
238 | return roots["impress-root-" + rootId];
239 | }
240 |
241 | // data of all presentation steps
242 | var stepsData = {};
243 |
244 | // element of currently active step
245 | var activeStep = null;
246 |
247 | // current state (position, rotation and scale) of the presentation
248 | var currentState = null;
249 |
250 | // array of step elements
251 | var steps = null;
252 |
253 | // configuration options
254 | var config = null;
255 |
256 | // scale factor of the browser window
257 | var windowScale = null;
258 |
259 | // root presentation elements
260 | var root = byId( rootId );
261 | var canvas = document.createElement("div");
262 |
263 | var initialized = false;
264 |
265 | // STEP EVENTS
266 | //
267 | // There are currently two step events triggered by impress.js
268 | // `impress:stepenter` is triggered when the step is shown on the
269 | // screen (the transition from the previous one is finished) and
270 | // `impress:stepleave` is triggered when the step is left (the
271 | // transition to next step just starts).
272 |
273 | // reference to last entered step
274 | var lastEntered = null;
275 |
276 | // `onStepEnter` is called whenever the step element is entered
277 | // but the event is triggered only if the step is different than
278 | // last entered step.
279 | var onStepEnter = function (step) {
280 | if (lastEntered !== step) {
281 | triggerEvent(step, "impress:stepenter");
282 | lastEntered = step;
283 | }
284 | };
285 |
286 | // `onStepLeave` is called whenever the step element is left
287 | // but the event is triggered only if the step is the same as
288 | // last entered step.
289 | var onStepLeave = function (step) {
290 | if (lastEntered === step) {
291 | triggerEvent(step, "impress:stepleave");
292 | lastEntered = null;
293 | }
294 | };
295 |
296 | // `initStep` initializes given step element by reading data from its
297 | // data attributes and setting correct styles.
298 | var initStep = function ( el, idx ) {
299 | var data = el.dataset,
300 | step = {
301 | translate: {
302 | x: toNumber(data.x),
303 | y: toNumber(data.y),
304 | z: toNumber(data.z)
305 | },
306 | rotate: {
307 | x: toNumber(data.rotateX),
308 | y: toNumber(data.rotateY),
309 | z: toNumber(data.rotateZ || data.rotate)
310 | },
311 | scale: toNumber(data.scale, 1),
312 | el: el
313 | };
314 |
315 | if ( !el.id ) {
316 | el.id = "step-" + (idx + 1);
317 | }
318 |
319 | stepsData["impress-" + el.id] = step;
320 |
321 | css(el, {
322 | position: "absolute",
323 | transform: "translate(-50%,-50%)" +
324 | translate(step.translate) +
325 | rotate(step.rotate) +
326 | scale(step.scale),
327 | transformStyle: "preserve-3d"
328 | });
329 | };
330 |
331 | // `init` API function that initializes (and runs) the presentation.
332 | var init = function () {
333 | if (initialized) { return; }
334 |
335 | // First we set up the viewport for mobile devices.
336 | // For some reason iPad goes nuts when it is not done properly.
337 | var meta = $("meta[name='viewport']") || document.createElement("meta");
338 | meta.content = "width=device-width, minimum-scale=1, maximum-scale=1, user-scalable=no";
339 | if (meta.parentNode !== document.head) {
340 | meta.name = 'viewport';
341 | document.head.appendChild(meta);
342 | }
343 |
344 | // initialize configuration object
345 | var rootData = root.dataset;
346 | config = {
347 | width: toNumber( rootData.width, defaults.width ),
348 | height: toNumber( rootData.height, defaults.height ),
349 | maxScale: toNumber( rootData.maxScale, defaults.maxScale ),
350 | minScale: toNumber( rootData.minScale, defaults.minScale ),
351 | perspective: toNumber( rootData.perspective, defaults.perspective ),
352 | transitionDuration: toNumber( rootData.transitionDuration, defaults.transitionDuration )
353 | };
354 |
355 | windowScale = computeWindowScale( config );
356 |
357 | // wrap steps with "canvas" element
358 | arrayify( root.childNodes ).forEach(function ( el ) {
359 | canvas.appendChild( el );
360 | });
361 | root.appendChild(canvas);
362 |
363 | // set initial styles
364 | document.documentElement.style.height = "100%";
365 |
366 | css(body, {
367 | height: "100%",
368 | overflow: "hidden"
369 | });
370 |
371 | var rootStyles = {
372 | position: "absolute",
373 | transformOrigin: "top left",
374 | transition: "all 0s ease-in-out",
375 | transformStyle: "preserve-3d"
376 | };
377 |
378 | css(root, rootStyles);
379 | css(root, {
380 | top: "50%",
381 | left: "50%",
382 | transform: perspective( config.perspective/windowScale ) + scale( windowScale )
383 | });
384 | css(canvas, rootStyles);
385 |
386 | body.classList.remove("impress-disabled");
387 | body.classList.add("impress-enabled");
388 |
389 | // get and init steps
390 | steps = $$(".step", root);
391 | steps.forEach( initStep );
392 |
393 | // set a default initial state of the canvas
394 | currentState = {
395 | translate: { x: 0, y: 0, z: 0 },
396 | rotate: { x: 0, y: 0, z: 0 },
397 | scale: 1
398 | };
399 |
400 | initialized = true;
401 |
402 | triggerEvent(root, "impress:init", { api: roots[ "impress-root-" + rootId ] });
403 | };
404 |
405 | // `getStep` is a helper function that returns a step element defined by parameter.
406 | // If a number is given, step with index given by the number is returned, if a string
407 | // is given step element with such id is returned, if DOM element is given it is returned
408 | // if it is a correct step element.
409 | var getStep = function ( step ) {
410 | if (typeof step === "number") {
411 | step = step < 0 ? steps[ steps.length + step] : steps[ step ];
412 | } else if (typeof step === "string") {
413 | step = byId(step);
414 | }
415 | return (step && step.id && stepsData["impress-" + step.id]) ? step : null;
416 | };
417 |
418 | // used to reset timeout for `impress:stepenter` event
419 | var stepEnterTimeout = null;
420 |
421 | // `goto` API function that moves to step given with `el` parameter (by index, id or element),
422 | // with a transition `duration` optionally given as second parameter.
423 | var goto = function ( el, duration ) {
424 |
425 | if ( !initialized || !(el = getStep(el)) ) {
426 | // presentation not initialized or given element is not a step
427 | return false;
428 | }
429 |
430 | // Sometimes it's possible to trigger focus on first link with some keyboard action.
431 | // Browser in such a case tries to scroll the page to make this element visible
432 | // (even that body overflow is set to hidden) and it breaks our careful positioning.
433 | //
434 | // So, as a lousy (and lazy) workaround we will make the page scroll back to the top
435 | // whenever slide is selected
436 | //
437 | // If you are reading this and know any better way to handle it, I'll be glad to hear about it!
438 | window.scrollTo(0, 0);
439 |
440 | var step = stepsData["impress-" + el.id];
441 |
442 | if ( activeStep ) {
443 | activeStep.classList.remove("active");
444 | body.classList.remove("impress-on-" + activeStep.id);
445 | }
446 | el.classList.add("active");
447 |
448 | body.classList.add("impress-on-" + el.id);
449 |
450 | // compute target state of the canvas based on given step
451 | var target = {
452 | rotate: {
453 | x: -step.rotate.x,
454 | y: -step.rotate.y,
455 | z: -step.rotate.z
456 | },
457 | translate: {
458 | x: -step.translate.x,
459 | y: -step.translate.y,
460 | z: -step.translate.z
461 | },
462 | scale: 1 / step.scale
463 | };
464 |
465 | // Check if the transition is zooming in or not.
466 | //
467 | // This information is used to alter the transition style:
468 | // when we are zooming in - we start with move and rotate transition
469 | // and the scaling is delayed, but when we are zooming out we start
470 | // with scaling down and move and rotation are delayed.
471 | var zoomin = target.scale >= currentState.scale;
472 |
473 | duration = toNumber(duration, config.transitionDuration);
474 | var delay = (duration / 2);
475 |
476 | // if the same step is re-selected, force computing window scaling,
477 | // because it is likely to be caused by window resize
478 | if (el === activeStep) {
479 | windowScale = computeWindowScale(config);
480 | }
481 |
482 | var targetScale = target.scale * windowScale;
483 |
484 | // trigger leave of currently active element (if it's not the same step again)
485 | if (activeStep && activeStep !== el) {
486 | onStepLeave(activeStep);
487 | }
488 |
489 | // Now we alter transforms of `root` and `canvas` to trigger transitions.
490 | //
491 | // And here is why there are two elements: `root` and `canvas` - they are
492 | // being animated separately:
493 | // `root` is used for scaling and `canvas` for translate and rotations.
494 | // Transitions on them are triggered with different delays (to make
495 | // visually nice and 'natural' looking transitions), so we need to know
496 | // that both of them are finished.
497 | css(root, {
498 | // to keep the perspective look similar for different scales
499 | // we need to 'scale' the perspective, too
500 | transform: perspective( config.perspective / targetScale ) + scale( targetScale ),
501 | transitionDuration: duration + "ms",
502 | transitionDelay: (zoomin ? delay : 0) + "ms"
503 | });
504 |
505 | css(canvas, {
506 | transform: rotate(target.rotate, true) + translate(target.translate),
507 | transitionDuration: duration + "ms",
508 | transitionDelay: (zoomin ? 0 : delay) + "ms"
509 | });
510 |
511 | // Here is a tricky part...
512 | //
513 | // If there is no change in scale or no change in rotation and translation, it means there was actually
514 | // no delay - because there was no transition on `root` or `canvas` elements.
515 | // We want to trigger `impress:stepenter` event in the correct moment, so here we compare the current
516 | // and target values to check if delay should be taken into account.
517 | //
518 | // I know that this `if` statement looks scary, but it's pretty simple when you know what is going on
519 | // - it's simply comparing all the values.
520 | if ( currentState.scale === target.scale ||
521 | (currentState.rotate.x === target.rotate.x && currentState.rotate.y === target.rotate.y &&
522 | currentState.rotate.z === target.rotate.z && currentState.translate.x === target.translate.x &&
523 | currentState.translate.y === target.translate.y && currentState.translate.z === target.translate.z) ) {
524 | delay = 0;
525 | }
526 |
527 | // store current state
528 | currentState = target;
529 | activeStep = el;
530 |
531 | // And here is where we trigger `impress:stepenter` event.
532 | // We simply set up a timeout to fire it taking transition duration (and possible delay) into account.
533 | //
534 | // I really wanted to make it in more elegant way. The `transitionend` event seemed to be the best way
535 | // to do it, but the fact that I'm using transitions on two separate elements and that the `transitionend`
536 | // event is only triggered when there was a transition (change in the values) caused some bugs and
537 | // made the code really complicated, cause I had to handle all the conditions separately. And it still
538 | // needed a `setTimeout` fallback for the situations when there is no transition at all.
539 | // So I decided that I'd rather make the code simpler than use shiny new `transitionend`.
540 | //
541 | // If you want learn something interesting and see how it was done with `transitionend` go back to
542 | // version 0.5.2 of impress.js: http://github.com/bartaz/impress.js/blob/0.5.2/js/impress.js
543 | window.clearTimeout(stepEnterTimeout);
544 | stepEnterTimeout = window.setTimeout(function() {
545 | onStepEnter(activeStep);
546 | }, duration + delay);
547 |
548 | return el;
549 | };
550 |
551 | // `prev` API function goes to previous step (in document order)
552 | var prev = function () {
553 | var prev = steps.indexOf( activeStep ) - 1;
554 | prev = prev >= 0 ? steps[ prev ] : steps[ steps.length-1 ];
555 |
556 | return goto(prev);
557 | };
558 |
559 | // `next` API function goes to next step (in document order)
560 | var next = function () {
561 | var next = steps.indexOf( activeStep ) + 1;
562 | next = next < steps.length ? steps[ next ] : steps[ 0 ];
563 |
564 | return goto(next);
565 | };
566 |
567 | // Adding some useful classes to step elements.
568 | //
569 | // All the steps that have not been shown yet are given `future` class.
570 | // When the step is entered the `future` class is removed and the `present`
571 | // class is given. When the step is left `present` class is replaced with
572 | // `past` class.
573 | //
574 | // So every step element is always in one of three possible states:
575 | // `future`, `present` and `past`.
576 | //
577 | // There classes can be used in CSS to style different types of steps.
578 | // For example the `present` class can be used to trigger some custom
579 | // animations when step is shown.
580 | root.addEventListener("impress:init", function(){
581 | // STEP CLASSES
582 | steps.forEach(function (step) {
583 | step.classList.add("future");
584 | });
585 |
586 | root.addEventListener("impress:stepenter", function (event) {
587 | event.target.classList.remove("past");
588 | event.target.classList.remove("future");
589 | event.target.classList.add("present");
590 | }, false);
591 |
592 | root.addEventListener("impress:stepleave", function (event) {
593 | event.target.classList.remove("present");
594 | event.target.classList.add("past");
595 | }, false);
596 |
597 | }, false);
598 |
599 | // Adding hash change support.
600 | root.addEventListener("impress:init", function(){
601 |
602 | // last hash detected
603 | var lastHash = "";
604 |
605 | // `#/step-id` is used instead of `#step-id` to prevent default browser
606 | // scrolling to element in hash.
607 | //
608 | // And it has to be set after animation finishes, because in Chrome it
609 | // makes transtion laggy.
610 | // BUG: http://code.google.com/p/chromium/issues/detail?id=62820
611 | root.addEventListener("impress:stepenter", function (event) {
612 | window.location.hash = lastHash = "#/" + event.target.id;
613 | }, false);
614 |
615 | window.addEventListener("hashchange", function () {
616 | // When the step is entered hash in the location is updated
617 | // (just few lines above from here), so the hash change is
618 | // triggered and we would call `goto` again on the same element.
619 | //
620 | // To avoid this we store last entered hash and compare.
621 | if (window.location.hash !== lastHash) {
622 | goto( getElementFromHash() );
623 | }
624 | }, false);
625 |
626 | // START
627 | // by selecting step defined in url or first step of the presentation
628 | goto(getElementFromHash() || steps[0], 0);
629 | }, false);
630 |
631 | body.classList.add("impress-disabled");
632 |
633 | // store and return API for given impress.js root element
634 | return (roots[ "impress-root-" + rootId ] = {
635 | init: init,
636 | goto: goto,
637 | next: next,
638 | prev: prev
639 | });
640 |
641 | };
642 |
643 | // flag that can be used in JS to check if browser have passed the support test
644 | impress.supported = impressSupported;
645 |
646 | })(document, window);
647 |
648 | // NAVIGATION EVENTS
649 |
650 | // As you can see this part is separate from the impress.js core code.
651 | // It's because these navigation actions only need what impress.js provides with
652 | // its simple API.
653 | //
654 | // In future I think about moving it to make them optional, move to separate files
655 | // and treat more like a 'plugins'.
656 | (function ( document, window ) {
657 | 'use strict';
658 |
659 | // throttling function calls, by Remy Sharp
660 | // http://remysharp.com/2010/07/21/throttling-function-calls/
661 | var throttle = function (fn, delay) {
662 | var timer = null;
663 | return function () {
664 | var context = this, args = arguments;
665 | clearTimeout(timer);
666 | timer = setTimeout(function () {
667 | fn.apply(context, args);
668 | }, delay);
669 | };
670 | };
671 |
672 | // wait for impress.js to be initialized
673 | document.addEventListener("impress:init", function (event) {
674 | // Getting API from event data.
675 | // So you don't event need to know what is the id of the root element
676 | // or anything. `impress:init` event data gives you everything you
677 | // need to control the presentation that was just initialized.
678 | var api = event.detail.api;
679 |
680 | // KEYBOARD NAVIGATION HANDLERS
681 |
682 | // Prevent default keydown action when one of supported key is pressed.
683 | document.addEventListener("keydown", function ( event ) {
684 | if ( event.keyCode === 9 || ( event.keyCode >= 32 && event.keyCode <= 34 ) || (event.keyCode >= 37 && event.keyCode <= 40) ) {
685 | event.preventDefault();
686 | }
687 | }, false);
688 |
689 | // Trigger impress action (next or prev) on keyup.
690 |
691 | // Supported keys are:
692 | // [space] - quite common in presentation software to move forward
693 | // [up] [right] / [down] [left] - again common and natural addition,
694 | // [pgdown] / [pgup] - often triggered by remote controllers,
695 | // [tab] - this one is quite controversial, but the reason it ended up on
696 | // this list is quite an interesting story... Remember that strange part
697 | // in the impress.js code where window is scrolled to 0,0 on every presentation
698 | // step, because sometimes browser scrolls viewport because of the focused element?
699 | // Well, the [tab] key by default navigates around focusable elements, so clicking
700 | // it very often caused scrolling to focused element and breaking impress.js
701 | // positioning. I didn't want to just prevent this default action, so I used [tab]
702 | // as another way to moving to next step... And yes, I know that for the sake of
703 | // consistency I should add [shift+tab] as opposite action...
704 | document.addEventListener("keyup", function ( event ) {
705 | if ( event.keyCode === 9 || ( event.keyCode >= 32 && event.keyCode <= 34 ) || (event.keyCode >= 37 && event.keyCode <= 40) ) {
706 | switch( event.keyCode ) {
707 | case 33: // pg up
708 | case 37: // left
709 | case 38: // up
710 | api.prev();
711 | break;
712 | case 9: // tab
713 | case 32: // space
714 | case 34: // pg down
715 | case 39: // right
716 | case 40: // down
717 | api.next();
718 | break;
719 | }
720 |
721 | event.preventDefault();
722 | }
723 | }, false);
724 |
725 | // delegated handler for clicking on the links to presentation steps
726 | document.addEventListener("click", function ( event ) {
727 | // event delegation with "bubbling"
728 | // check if event target (or any of its parents is a link)
729 | var target = event.target;
730 | while ( (target.tagName !== "A") &&
731 | (target !== document.documentElement) ) {
732 | target = target.parentNode;
733 | }
734 |
735 | if ( target.tagName === "A" ) {
736 | var href = target.getAttribute("href");
737 |
738 | // if it's a link to presentation step, target this step
739 | if ( href && href[0] === '#' ) {
740 | target = document.getElementById( href.slice(1) );
741 | }
742 | }
743 |
744 | if ( api.goto(target) ) {
745 | event.stopImmediatePropagation();
746 | event.preventDefault();
747 | }
748 | }, false);
749 |
750 | // delegated handler for clicking on step elements
751 | document.addEventListener("click", function ( event ) {
752 | var target = event.target;
753 | // find closest step element that is not active
754 | while ( !(target.classList.contains("step") && !target.classList.contains("active")) &&
755 | (target !== document.documentElement) ) {
756 | target = target.parentNode;
757 | }
758 |
759 | if ( api.goto(target) ) {
760 | event.preventDefault();
761 | }
762 | }, false);
763 |
764 | // touch handler to detect taps on the left and right side of the screen
765 | // based on awesome work of @hakimel: https://github.com/hakimel/reveal.js
766 | document.addEventListener("touchstart", function ( event ) {
767 | if (event.touches.length === 1) {
768 | var x = event.touches[0].clientX,
769 | width = window.innerWidth * 0.3,
770 | result = null;
771 |
772 | if ( x < width ) {
773 | result = api.prev();
774 | } else if ( x > window.innerWidth - width ) {
775 | result = api.next();
776 | }
777 |
778 | if (result) {
779 | event.preventDefault();
780 | }
781 | }
782 | }, false);
783 |
784 | // rescale presentation when window is resized
785 | window.addEventListener("resize", throttle(function () {
786 | // force going to active step again, to trigger rescaling
787 | api.goto( document.querySelector(".active"), 500 );
788 | }, 250), false);
789 |
790 | }, false);
791 |
792 | })(document, window);
793 |
794 | // THAT'S ALL FOLKS!
795 | //
796 | // Thanks for reading it all.
797 | // Or thanks for scrolling down and reading the last part.
798 | //
799 | // I've learnt a lot when building impress.js and I hope this code and comments
800 | // will help somebody learn at least some part of it.
801 |
--------------------------------------------------------------------------------
/src/jekyll/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: Introduction to Functional Programming
4 | ---
5 |
6 | # Functional Patterns #
7 |
8 | [Start Presentation](preso.html) [older computers](simple-preso.html)
9 |
10 | [Printable Presentation](print.html)
11 |
12 | [Fork me on GitHub](https://github.com/jsuereth/intro-to-fp)
13 |
--------------------------------------------------------------------------------
/src/jekyll/preso.html:
--------------------------------------------------------------------------------
1 | ---
2 | layout: presentation
3 | title: Introduction to Functional Programming
4 | ---
5 |
6 | {% for post in site.posts reversed %}
7 | {% include slide.html %}
8 | {% endfor %}
9 | {% if site.overview %}
10 |
11 | {% endif %}
--------------------------------------------------------------------------------
/src/jekyll/print.html:
--------------------------------------------------------------------------------
1 | ---
2 | layout: print
3 | title: Introduction to Functional Programming Patterns
4 | ---
5 |
6 | {% for post in site.posts reversed %}
7 | {% include slide.html %}
8 | {% endfor %}
9 | {% if site.overview %}
10 |
11 | {% endif %}
--------------------------------------------------------------------------------
/src/jekyll/simple-preso.html:
--------------------------------------------------------------------------------
1 | ---
2 | layout: simplepresentation
3 | title: Introduction to Functional Programming
4 | ---
5 |
6 | {% for post in site.posts reversed %}
7 | {% include simpleslide.html %}
8 | {% endfor %}
9 |
--------------------------------------------------------------------------------
/src/main/scala/futures/App.scala:
--------------------------------------------------------------------------------
1 | package futures
2 |
3 | import concurrent._
4 | import concurrent.duration._
5 |
6 | object StatApp extends App {
7 |
8 | implicit val ctx = ExecutionContext.Implicits.global
9 | val api = GhApi.make
10 | val service = new SpecificStatisticsService(api)
11 | for(arg <- args) {
12 | val stats = Await.result(service.userStatistics(arg), 60 seconds)
13 | println(stats)
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/scala/futures/api.scala:
--------------------------------------------------------------------------------
1 | package futures
2 |
3 | import concurrent.Future
4 | import model._
5 |
6 | trait GhApi {
7 | def projects(user: String): Future[Seq[Project]]
8 | def pullrequests(proj: Project): Future[Seq[PullRequest]]
9 | def collaborators(proj: Project): Future[Seq[Collaborator]]
10 | }
11 |
12 | object GhApi {
13 | def make: GhApi = LivGhApi
14 | }
15 |
16 | // We delegate for laziness. The other API has more typing than this one, so it has the impl.
17 | object LivGhApi extends GhApi {
18 | implicit val ctx = concurrent.ExecutionContext.Implicits.global
19 | def projects(user: String): Future[Seq[Project]] =
20 | generic.LiveGhApi.projects(user)
21 | def pullrequests(proj: Project): Future[Seq[PullRequest]] =
22 | generic.LiveGhApi.pullrequests(proj)
23 | def collaborators(proj: Project): Future[Seq[Collaborator]] =
24 | generic.LiveGhApi.collaborators(proj)
25 | }
--------------------------------------------------------------------------------
/src/main/scala/futures/service.scala:
--------------------------------------------------------------------------------
1 | package futures
2 |
3 | import concurrent._
4 | import model._
5 |
6 | class SpecificStatisticsService(api: GhApi)(implicit ctx: ExecutionContext) {
7 |
8 | def projectStatistics(project: Project): Future[ProjectStatistics] = {
9 | val pullRequests = api pullrequests project
10 | val collaborators = api collaborators project
11 | pullRequests zip collaborators map {
12 | case (prs, cs) => ProjectStatistics(project, cs, prs)
13 | }
14 | }
15 |
16 | def userStatistics(user: String): Future[Statistics] =
17 | for {
18 | projects <- api projects user
19 | stats <- Future.traverse(projects)(projectStatistics)
20 | } yield Statistics(user, stats)
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/scala/generic/App.scala:
--------------------------------------------------------------------------------
1 | package generic
2 |
3 | import concurrent._
4 | import concurrent.duration._
5 | import Instances._
6 |
7 | object StatApp extends App {
8 | implicit val ctx = ExecutionContext.Implicits.global
9 | val service = new GenericStatisticsService(GhApi.makeNonBlocking)
10 | for(arg <- args) {
11 | val stats = Await.result(service.userStatistics(arg), 60 seconds)
12 | println()
13 | println(stats)
14 | println()
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/scala/generic/abstractions.scala:
--------------------------------------------------------------------------------
1 | package generic
2 |
3 | /** Represents a higher-kinded type that can take any value and encapsulate it. */
4 | trait Pointed[P[_]] {
5 | def point[A](a: A): P[A]
6 | }
7 |
8 |
9 | /** represents a container of a value where the contained
10 | * value(s) may be altered.
11 | */
12 | trait Functor[F[_]] {
13 | def map[A,B](a: F[A])(f: A => B): F[B]
14 | }
15 |
16 |
17 | /** Represents the ability to *join* a computation in some
18 | * context.
19 | */
20 | trait Applicative[A[_]] extends Pointed[A] with Functor[A] {
21 | def ap[B,C](fa: A[B])(f: A[B => C]): A[C]
22 | }
23 |
24 | /** Represents a 'container' that can thread computations
25 | *
26 | */
27 | trait Monad[M[_]] extends Applicative[M] {
28 | /** 'lifts' a value into a monadic context. */
29 | def flatMap[A,B](ma: M[A])(f: A => M[B]): M[B]
30 |
31 |
32 | // Default horrible implementation.
33 | override def map[A,B](ma: M[A])(f: A => B): M[B] =
34 | flatMap(ma) { a => point(f(a)) }
35 | override def ap[B,C](ma: M[B])(f: M[B => C]): M[C] =
36 | flatMap(ma) { a => map(f) { f => f(a) } }
37 | }
38 |
39 | /** Represents something that can be traversed inside some context. */
40 | trait Traverse[Coll[_]] {
41 | def traverse[Context[_]: Applicative,A,B](a: Coll[A])(f: A => Context[B]): Context[Coll[B]]
42 | }
43 |
44 |
45 |
--------------------------------------------------------------------------------
/src/main/scala/generic/api.scala:
--------------------------------------------------------------------------------
1 | package generic
2 |
3 | import model._
4 |
5 |
6 | trait GhApi[Context[_]] {
7 | def projects(user: String): Context[Seq[Project]]
8 | def pullrequests(proj: Project): Context[Seq[PullRequest]]
9 |
10 | def collaborators(proj: Project): Context[Seq[Collaborator]]
11 | }
12 |
13 | object GhApi {
14 | def makeNonBlocking: GhApi[concurrent.Future] = LiveGhApi
15 | }
16 |
17 |
--------------------------------------------------------------------------------
/src/main/scala/generic/contexts.scala:
--------------------------------------------------------------------------------
1 | package generic
2 |
3 | import concurrent.Future
4 |
5 |
6 | object Contexts {
7 | type SingleThreaded[X] = X
8 | type Concurrent[X] = Future[X]
9 | }
10 |
--------------------------------------------------------------------------------
/src/main/scala/generic/ghservice.scala:
--------------------------------------------------------------------------------
1 | package generic
2 |
3 | import concurrent.Future
4 | import concurrent.promise
5 | import util.parsing.json.{JSON,JSONType,JSONObject,JSONArray}
6 | import scala.util.control.NonFatal
7 | import model._
8 |
9 | case class AuthApp(name: String, url: String)
10 | case class Authorization(id: String, token: String, app: AuthApp, note: Option[String])
11 |
12 | object Authenticate {
13 | import dispatch._
14 | import Defaults._
15 | private[this] val authorizations =
16 | url("https://api.github.com/authorizations").setHeader("User-Agent", "github.com/jsuereth/intro-to-fp")
17 |
18 | val authScopes = """{
19 | "scopes": [
20 | "repo"
21 | ],
22 | "note": "demo API Access"
23 | }"""
24 |
25 | /** This method looks for a previous GH authorization for this API and retrieves it, or
26 | * creates a new one.
27 | */
28 | def authenticate(user: String, pw: String): Authorization = {
29 | val previousAuth: Option[Authorization] =
30 | (getAuthentications(user,pw) filter (_.note == Some("demo API Access"))).headOption
31 | previousAuth foreach (auth => println("Found previous github auth for: " + auth.app))
32 | previousAuth getOrElse makeAuthentication(user, pw)
33 | }
34 |
35 | private def parseAuthorization(json: Any): Authorization = {
36 | val map = json.asInstanceOf[Map[String, Any]]
37 | val appMap = map("app").asInstanceOf[Map[String,Any]]
38 | Authorization(
39 | map("id").toString,
40 | map("token").toString,
41 | AuthApp(appMap("name").toString, appMap("url").toString),
42 | map get "note" filterNot (_ == null) map (_.toString))
43 | }
44 |
45 | def makeAuthentication(user: String, pw: String): Authorization = {
46 | val future = Http(authorizations.POST.as_!(user, pw) << authScopes OK as.String)
47 | val string = future()
48 | System.out.println("Creating new authentication token.")
49 | parseAuthorization(JSON.parseFull(string).get)
50 | }
51 | //Http(authorizations.POST.as_!(user, pw) << authScopes >- parseJsonTo[Authorization])
52 |
53 | def getAuthentications(user: String, pw: String): List[Authorization] = {
54 | val future = Http(authorizations.as_!(user, pw) OK as.String)
55 | val string = future()
56 | val list = JSON.parseFull(string).get
57 | list match {
58 | case list: Seq[Any] => (list map parseAuthorization)(collection.breakOut)
59 | case map: Map[String, Any] => List(parseAuthorization(map))
60 | }
61 | }
62 |
63 | def deleteAuthentication(auth: Authorization, user: String, pw: String): Unit = {
64 | val future = Http((authorizations / auth.id).DELETE.as_!(user,pw))
65 | future()
66 | }
67 |
68 | def deleteAuthentications(user: String, pw: String): Unit =
69 | getAuthentications(user, pw) foreach { a =>
70 | deleteAuthentication(a, user, pw)
71 | }
72 | }
73 |
74 |
75 | object LiveGhApi extends GhApi[Future] {
76 | private final val githubUrl = "https://api.github.com"
77 |
78 | lazy val authorization: Authorization = {
79 | val props = new java.util.Properties
80 | val in = new java.io.FileInputStream(new java.io.File("github.properties"))
81 | try props.load(in)
82 | finally in.close()
83 | System.err.println("Authenticating user: " + props.getProperty("github.user"))
84 | Authenticate.authenticate(props.getProperty("github.user"), props.getProperty("github.pw"))
85 | }
86 |
87 | // THE BIG UGLY -> Generic grab JSON, parse with scala's json parser and
88 | // delegate extraction to
89 | private def rest[A](uri: String)(handleJson: Any => A): Future[A] = {
90 | val result = promise[A]
91 | import dispatch._
92 | import Defaults._
93 | Http(url(uri).setHeader("User-Agent", "github.com/jsuereth/intro-to-fp").setHeader("Authorization", s"token ${authorization.token}") OK as.String) foreach {
94 | json =>
95 | // TODO - Parse and fill out our result
96 | JSON.parseFull(json) match {
97 | case None => result.failure(new RuntimeException("Unable to parse json response: " + json))
98 | case Some(value) =>
99 | try result.success(handleJson(value))
100 | catch {
101 | case NonFatal(e) =>
102 | //System.err.println("Failed to parse: " + json)
103 | result.failure(e)
104 | }
105 | }
106 | }
107 | result.future
108 | }
109 |
110 | def projects(user: String): Future[Seq[Project]] =
111 | rest(s"${githubUrl}/users/${user}/repos?per_page=100") {
112 | case data: Seq[Map[String,Any]] =>
113 | data map { json => Project(user, json("name").toString) }
114 | }
115 | def pullrequests(proj: Project): Future[Seq[PullRequest]] =
116 | rest(s"${githubUrl}/repos/${proj.owner}/${proj.name}/pulls?per_page=100&state=closed") {
117 | case data: Seq[Map[String,Any]] =>
118 | data map { json => PullRequest(
119 | proj,
120 | json("number").toString,
121 | json.get("user").asInstanceOf[Option[Map[String,Any]]].map(_("login").toString).getOrElse(""),
122 | json.get("merged_at").isDefined)}
123 | }
124 |
125 | def collaborators(proj: Project): Future[Seq[Collaborator]] =
126 | rest(s"${githubUrl}/repos/${proj.owner}/${proj.name}/collaborators?per_page=100") {
127 | case data: Seq[Map[String, Any]] =>
128 | data map (json => Collaborator(json("login").toString))
129 | }
130 | }
--------------------------------------------------------------------------------
/src/main/scala/generic/instances.scala:
--------------------------------------------------------------------------------
1 | package generic
2 |
3 | import Contexts.Concurrent
4 | import Contexts.SingleThreaded
5 | import concurrent._
6 |
7 |
8 | object Instances {
9 |
10 | implicit object SeqAbstractions extends Monad[Seq] with Traverse[Seq] {
11 | def point[A](x: A): Seq[A] = Seq(x)
12 | override def map[A, B](x: Seq[A])(f: A => B): Seq[B] =
13 | x map f
14 | def flatMap[A, B](x: Seq[A])(f: A => Seq[B]): Seq[B] =
15 | x flatMap f
16 | def traverse[Context[_]: Applicative,A,B](a: Seq[A])(f: A => Context[B]): Context[Seq[B]] = {
17 | // TODO - best performance?
18 | val ap = implicitly[Applicative[Context]]
19 | val mapped: Seq[Context[B]] = a map f
20 | val init = ap point Seq.empty[B]
21 | mapped.foldLeft(init) { (current, el) =>
22 | val appendTransformed: Context[Seq[B] => Seq[B]] =
23 | ap.map(el) { t => (start: Seq[B]) => start :+ t }
24 | ap.ap(current)(appendTransformed)
25 | }
26 | }
27 | }
28 |
29 |
30 | import Contexts._
31 | implicit object SingleThreadedAbstractions
32 | extends Monad[SingleThreaded] {
33 | def point[A](x: A): SingleThreaded[A] = x
34 | override def map[A, B](x: SingleThreaded[A])(f: A => B): SingleThreaded[B] =
35 | f(x)
36 | def flatMap[A, B](x: SingleThreaded[A])(f: A => SingleThreaded[B]): SingleThreaded[B] =
37 | f(x)
38 | }
39 |
40 | final class ConcurrentAbstractions(implicit executor: ExecutionContext)
41 | extends Monad[Future] {
42 | def point[A](x: A): Future[A] = Future(x)
43 | override def map[A, B](x: Future[A])(f: A => B): Future[B] =
44 | x map f
45 | def flatMap[A, B](x: Future[A])(f: A => Future[B]): Future[B] =
46 | x flatMap f
47 | }
48 | implicit def concurrentAbs(implicit executor: ExecutionContext): ConcurrentAbstractions =
49 | new ConcurrentAbstractions
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/scala/generic/service.scala:
--------------------------------------------------------------------------------
1 | package generic
2 |
3 | import Instances.SeqAbstractions
4 | import Syntax.ops
5 | import Syntax.tuple2Ops
6 | import model._
7 |
8 |
9 | class GenericStatisticsService[Context[_]: Monad](api: GhApi[Context]) {
10 |
11 | def projectStatistics(project: Project): Context[ProjectStatistics] = {
12 | val pullRequests = api pullrequests project
13 | val collaborators = api collaborators project
14 | pullRequests zip collaborators map {
15 | case (prs, cs) => ProjectStatistics(project, cs, prs)
16 | }
17 | }
18 |
19 | def userStatistics(user: String): Context[Statistics] =
20 | for {
21 | projects <- api projects user
22 | stats <- projects traverse projectStatistics
23 | } yield Statistics(user, stats)
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/scala/generic/syntax.scala:
--------------------------------------------------------------------------------
1 | package generic
2 |
3 | object Syntax {
4 |
5 | // Helpers put on "container" types.
6 | final implicit class ops[M[_], A](val ma: M[A]) extends AnyVal{
7 | def map[B](f: A => B)(implicit ev: Functor[M]): M[B] =
8 | ev.map(ma)(f)
9 | def flatMap[B](f: A => M[B])(implicit ev: Monad[M]): M[B] =
10 | ev.flatMap(ma)(f)
11 | def zip[B](other: M[B])(implicit ev: Applicative[M]) =
12 | (ma, other) ap { (a, b) => a -> b }
13 | def traverse[Context[_], B](f: A => Context[B])(implicit ev: Traverse[M], ev2: Applicative[Context]): Context[M[B]] =
14 | ev.traverse(ma)(f)
15 | }
16 |
17 | // Helpers put on Tuple2 types.
18 | final implicit class tuple2Ops[M[_], A, B](val tuple2: (M[A], M[B])) extends AnyVal {
19 | def ap[C](f: (A,B) => C)(implicit ap: Applicative[M]) =
20 | ap.ap(tuple2._2)(tuple2._1 map f.curried)
21 | }
22 |
23 |
24 | // Helpers put on Tuple3 types.
25 | final implicit class tuple3Ops[M[_], A, B, C](val tuple: (M[A], M[B], M[C])) extends AnyVal {
26 | def ap[D](f: (A,B,C) => D)(implicit ap: Applicative[M]) =
27 | ap.ap(tuple._3)(ap.ap(tuple._2)(tuple._1 map f.curried))
28 | }
29 |
30 | // Helpers put on any type.
31 | final implicit class any2Ops[A](val a: A) extends AnyVal {
32 | def point[P[_]: Pointed] = implicitly[Pointed[P]] point a
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/scala/model/model.scala:
--------------------------------------------------------------------------------
1 | package model
2 |
3 |
4 | case class Project(owner: String, name: String)
5 | case class PullRequest(project: Project, id: String, contributor: String, merged: Boolean)
6 | case class Collaborator(name: String)
7 |
8 |
9 | case class ProjectStatistics(
10 | project: Project,
11 | collaborators: Seq[Collaborator],
12 | pullreqs: Seq[PullRequest]) {
13 |
14 | val mergedCount = pullreqs.filter(_.merged).size
15 | val mergePercent = (mergedCount / pullreqs.size.toDouble) * 100.0;
16 |
17 | val outsidePrs = pullreqs filterNot { pr =>
18 | collaborators exists (c => c.name == pr.contributor)
19 | }
20 | val outsideMerged = outsidePrs.filter(_.merged).size
21 | val outsideMergePercent = (outsideMerged / pullreqs.size.toDouble) * 100.0;
22 |
23 | override def toString =
24 | f"""|\t---- Project ${project.name} Statistics---
25 | |\t Pull requests: ${pullreqs.length}
26 | |\t %% Merged: ${mergePercent}%02.2f
27 | |\t %% Merged from Outside: ${outsideMergePercent}%02.2f""".stripMargin
28 | }
29 |
30 | case class Statistics(
31 | user: String,
32 | projects: Seq[ProjectStatistics]) {
33 |
34 | // Make sure they've had activity.
35 | val interestingProjects = projects filter (_.pullreqs.size > 5)
36 |
37 | override def toString =
38 | s"""|--- User ${user} Statitiscs
39 | |${interestingProjects mkString "\n"}"""
40 | }
--------------------------------------------------------------------------------
/src/site/.nojekyll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsuereth/intro-to-fp/5feab100c06a4feb3af2b9e675c6217e6fb5764a/src/site/.nojekyll
--------------------------------------------------------------------------------
/src/test/java/futures/ServiceSpec.scala:
--------------------------------------------------------------------------------
1 | package futures
2 |
3 | import org.specs2.mutable.Specification
4 | import concurrent._
5 | import concurrent.duration._
6 | import Duration.Inf
7 | import ExecutionContext.Implicits.global
8 | import model._
9 |
10 | object ServiceSpec extends Specification {
11 |
12 | "A Specific Statistics Service" should {
13 | "Find all projects" in {
14 | // Stubbed API
15 | val api = new GhApi {
16 | def projects(user: String) =
17 | Future(Seq(Project("jsuereth", "scala-arm"), Project("jsuereth", "intro-to-fp")))
18 | override def pullrequests(project: Project) = Future(project match {
19 | case p @ Project("jsuereth", "scala-arm") =>
20 | Seq(PullRequest(p, "1", "ThatOtherGuy", false))
21 | case _ => Seq.empty
22 | })
23 | override def collaborators(project: Project) = Future(project match {
24 | case p @ Project("jsuereth", "scala-arm") =>
25 | Seq(Collaborator("ThatOtherGuy"))
26 | case _ => Seq.empty
27 | })
28 | }
29 | val service = new SpecificStatisticsService(api)
30 | val results = Await.result(service.userStatistics("Josh"), Inf)
31 | results.user must equalTo("Josh")
32 | results.projects.size must equalTo(2)
33 |
34 | results.projects must contain(ProjectStatistics(
35 | Project("jsuereth", "scala-arm"),
36 | Seq(Collaborator("ThatOtherGuy")),
37 | Seq(PullRequest(Project("jsuereth", "scala-arm"), "1", "ThatOtherGuy", false)))
38 | )
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/test/java/generic/ServiceSpec.scala:
--------------------------------------------------------------------------------
1 | package generic
2 |
3 | import org.specs2.mutable.Specification
4 | import Instances.SingleThreadedAbstractions
5 | import model._
6 |
7 | object ServiceSpec extends Specification {
8 |
9 | "A Generic Statistics Service" should {
10 | "Find all projects" in {
11 | // Stubbed API
12 | val api = new GhApi[Contexts.SingleThreaded] {
13 | def projects(user: String) =
14 | Seq(Project("jsuereth", "scala-arm"), Project("jsuereth", "intro-to-fp"))
15 | override def pullrequests(project: Project) = project match {
16 | case p @ Project("jsuereth", "scala-arm") =>
17 | Seq(PullRequest(p, "1", "ThatOtherGuy", false))
18 | case _ => Seq.empty
19 | }
20 | override def collaborators(project: Project) = project match {
21 | case p @ Project("jsuereth", "scala-arm") =>
22 | Seq(Collaborator("ThatOtherGuy"))
23 | case _ => Seq.empty
24 | }
25 | }
26 | val service = new GenericStatisticsService(api)
27 | val results = service.userStatistics("Josh")
28 | results.user must equalTo("Josh")
29 | results.projects.size must equalTo(2)
30 |
31 | results.projects must contain(ProjectStatistics(
32 | Project("jsuereth", "scala-arm"),
33 | Seq(Collaborator("ThatOtherGuy")),
34 | Seq(PullRequest(Project("jsuereth", "scala-arm"), "1", "ThatOtherGuy", false)))
35 | )
36 | }
37 | }
38 | }
--------------------------------------------------------------------------------