(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
@Grapes([ | |
@Grab('org.gebish:geb-core:0.12.0'), | |
@Grab('org.seleniumhq.selenium:selenium-htmlunit-driver:2.45.0'), | |
@Grab('org.seleniumhq.selenium:selenium-support:2.45.0') | |
]) | |
import geb.Browser | |
import org.openqa.selenium.htmlunit.HtmlUnitDriver | |
def browser = new Browser(driver: new HtmlUnitDriver()) |
case class Heading(weight: Int, text: String) | |
case class Node(heading: Heading, children: List[Node]) | |
/** Converts a list of input headings into nested nodes */ | |
def toOutline(headings: List[Heading]): Node = { | |
def buildNodes(input: List[Heading]): List[Node] = input match { | |
case Nil => Nil | |
case head :: Nil => Node(head, Nil) :: Nil | |
case head +: tail => | |
tail.splitAt(tail.indexWhere(head.weight == _.weight)) match { |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
import sys, math | |
def get_bin(lat, lng): | |
'''bin position''' | |
lat = max(0, lat + 70) if lat < 0 else min(140, lat + 70) | |
lng = lng + 180 | |
return int(2 * lat) + 280 * int(2 * lng) |
case class Reader[C, A](g: C => A) { | |
def apply(c: C) = g(c) | |
def map[B](f: A => B): Reader[C, B] = | |
(c:C) => f(g(c)) | |
def flatMap[B](f: A => Reader[C, B]): Reader[C, B] = | |
(c:C) => f(g(c))(c) | |
} | |
object Reader { | |
implicit def Reader[A,B](f: A => B): Reader[A,B] = Reader(f) |