Skip to content

Instantly share code, notes, and snippets.

  1. General Background and Overview
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.geometry.Point2D;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.input.MouseEvent;
import javafx.stage.Stage;
import static javafx.scene.input.MouseEvent.*;
@headinthebox
headinthebox / gist:37c76829253388fd88e3
Last active August 29, 2015 14:02
Fun with Functional Programming

Exercise: Define foldl in terms of foldr

Recall the definition of folding a list from the right

    foldr :: (a -> b -> b) -> b -> [a] -> b
    foldr f b []     = b
    foldr f b (a:as) = f a (foldr f b as)

for example foldr f b [1,2,3] = f 1 (f 2 (f 3 b)).

A playful introduction to Rx

Learning Rx does not have to be boring or painful working your way through theoretical sermons about esoteric concepts like category theory and duality. Life is too short for that kind of abstract nonsense.

So what is a better way to spend a hot summer day with an ice-cold drink, or dually, a cold winter night with a piping hot drink, than to learn Rx by writing an awesome platform game. In this talk, I will walk you through many of the features of Rx by way of scripting a friendly bug to run across a lavish grass meadow and jump for the stars. In just a few tens of lines of code, we will leverage operators like map, flatMap, filter, scan, and many more to react to the keyboard, animate jumps, and perform collision detection. We will even use a test scheduler to make the game run at a speed we determine so we can easily debug and test our game.

We will use RxScala and IntelliJ to develop the game, but since Rx is language and platform agnos

object InferMyTypePlease {
def uncurried[A, B](src: List[A], f: A => B): List[B] = src.map(f)
def curried[A, B](src: List[A])(f: A => B): List[B] = uncurried(src, f)
}
object Scala {
import InferMyTypePlease._
def main(args: Array[String]): Unit = {
val xs = List(1,2,3)

The introduction to Reactive Programming you've been missing

(by @andrestaltz)

So you're curious in learning this new thing called (Functional) Reactive Programming (FRP).

Learning it is hard, even harder by the lack of good material. When I started, I tried looking for tutorials. I found only a handful of practical guides, but they just scratched the surface and never tackled the challenge of building the whole architecture around it. Library documentations often don't help when you're trying to understand some function. I mean, honestly, look at this:

Rx.Observable.prototype.flatMapLatest(selector, [thisArg])

Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.

  1. General Background and Overview
@headinthebox
headinthebox / Pager.java
Created November 5, 2015 19:03 — forked from mttkay/Pager.java
A simple Rx based pager
public class Pager<I, O> {
private static final Observable FINISH_SEQUENCE = Observable.never();
private PublishSubject<Observable<I>> pages;
private Observable<I> nextPage = finish();
private Subscription subscription = Subscriptions.empty();
private final PagingFunction<I> pagingFunction;
private final Func1<I, O> pageTransformer;
@headinthebox
headinthebox / Event-stream based GraphQL subscriptions.md
Created December 7, 2015 18:17 — forked from OlegIlyenko/Event-stream based GraphQL subscriptions.md
Event-stream based GraphQL subscriptions for real-time updates

In this gist I would like to describe an idea for GraphQL subscriptions. It was inspired by conversations about subscriptions in the GraphQL slack channel and different GH issues, like #89 and #411.

Conceptual Model

At the moment GraphQL allows 2 types of queries:

  • query
  • mutation

Reference implementation also adds the third type: subscription. It does not have any semantics yet, so here I would like to propose one possible semantics interpretation and the reasoning behind it.

@headinthebox
headinthebox / springer-free-maths-books.md
Created December 28, 2015 23:11 — forked from bishboria/springer-free-maths-books.md
Springer have made a bunch of maths books available for free, here are the direct links