This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// see this blogpost: http://sketchytech.blogspot.co.uk/2014/11/swift-how-to-draw-clock-face-using_12.html | |
import UIKit | |
class ViewController: UIViewController { | |
func rotateLayer(currentLayer:CALayer,dur:CFTimeInterval){ | |
var angle = degree2radian(360) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object TransducerUniversal { | |
type Reduct[-A, R] = (R, A) => R | |
trait Trans[+A, -B] { def apply[R](f: Reduct[A, R]): Reduct[B, R] } | |
def map[A, B](f: A => B): Trans[B, A] = new Trans[B, A] { def apply[R](rf: Reduct[B, R]) = (r, a) => rf(r, f(a)) } | |
def filter[A](p: A => Boolean): Trans[A, A] = new Trans[A, A] { def apply[R](rf: Reduct[A, R]) = (r, a) => if (p(a)) rf(r, a) else r } | |
def comp[A,B,C](t1 : Trans[A, B], t2 : Trans[C, A]): Trans[C, B] = new Trans[C, B] { def apply[R](rf: Reduct[C, R]) = t1(t2(rf)) } | |
def sequence[A, B](t: Trans[B, A], data: Seq[A]) = data.foldLeft(Seq[B]())(t(_ :+ _)) | |
implicit class Compable[A,B](t1: Trans[A, B]) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Transducer { | |
type RF[R, A] = (R, A) => R | |
def apply[A, B](f: A => B) = | |
new Transducer[B, A] { | |
def apply[R](rf: RF[R, B]) = (r, a) => rf(r, f(a)) | |
} | |
} | |
import Transducer.RF |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package scalax.collection | |
import scala.collection.mutable.ListBuffer | |
/** FoldTransformers and the views based on them are a Scala | |
* adaptation, and to some degree an extension, of Rich Hickey's | |
* transducers for Clojure. They show that the concepts can be | |
* implemented in a type-safe way, and that the implementation is | |
* quite beautiful. | |
*/ | |
object FoldingViews { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Simple monad to deal with multiple database transactions with same connection, their commits and rollbacks | |
// Something similar done in http://advorkovyy.blogspot.com.au/2010/10/transactional-monad-for-scala.html | |
import java.sql.Connection | |
trait DbTransaction[A] { | |
def unit: Connection => A | |
def map[B](f: A => B): DbTransaction[B] = DbTransaction { | |
connection => f(unit(connection)) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ahoy | |
import scala.collection.mutable | |
object transducer { | |
type Reducer[A, R] = R => A => R | |
trait Transducer[A, B] { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed trait Interact[A] | |
case class Ask(prompt: String) | |
extends Interact[String] | |
case class Tell(msg: String) | |
extends Interact[Unit] | |
trait Monad[M[_]] { | |
def pure[A](a: A): M[A] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class Identifier(id: Long) | |
case class Rectangle(x: Int, y: Int, width: Int, height: Int) | |
object QuadTree { | |
private val MAX_OBJECTS = 2 | |
private val MAX_LEVELS = 5 | |
private val PARENT_NODE = -1 | |
private val TOP_RIGHT = 0 | |
private val TOP_LEFT = 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.liveperson.predictivedialer.examples.misc | |
import scala.annotation.tailrec | |
import scala.util.Try | |
/** | |
* Created with IntelliJ IDEA. | |
* User: mishaelr | |
* Date: 5/14/14 | |
* Time: 5:18 PM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.kafecho.learning.monad | |
import java.util.UUID | |
/** My attempt at implementing the Reader Monad concept. | |
* The Reader Monad encapsulates a computation which: | |
* - requires a dependency of type D | |
* - produces values of type A. | |
*/ | |
case class Reader[D, A](computation: D => A) { |