This file contains 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
import java.util.concurrent.ConcurrentHashMap | |
import java.util.concurrent.CountDownLatch | |
import akka.actor.Actor | |
import akka.dispatch.Future | |
import akka.actor.ActorSystem | |
import akka.actor._ | |
import scala.collection.JavaConversions._ | |
import scala.collection.JavaConversions | |
import akka.pattern._ | |
import akka.util.Timeout |
This file contains 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
import java.util.concurrent.ConcurrentHashMap | |
import java.util.concurrent.CountDownLatch | |
import akka.dispatch.Future | |
import akka.dispatch.Promise | |
import scala.collection.JavaConversions._ | |
import scala.collection.JavaConversions | |
import akka.dispatch.ExecutionContext | |
import java.util.concurrent.Executors | |
import java.util.concurrent.atomic.AtomicReference |
This file contains 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
//Reader Monad and its extension class to give it SelectMany(bind/flatMap) capabilities for use in LINQ queries | |
public static class ReaderMonadExt | |
{ | |
public static ReaderMonad<T, C> SelectMany<T, A, B, C>(this ReaderMonad<T, A> rm, Func<A, ReaderMonad<T, B>> bindf, Func<A, B, C> select) | |
{ | |
return new ReaderMonad<T, C>(t => | |
{ | |
var a = rm.Run(t); | |
return select(a, bindf(a).Run(t)); | |
}); |
This file contains 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 vsxmpp | |
import scalaz.EitherT | |
import scalaz._ | |
import Scalaz._ | |
case class ABC(s:String) | |
object ABC { | |
This file contains 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
using System; | |
using System.Threading; | |
using XSharpx; | |
using System.Collections; | |
using System.Net; | |
namespace TestProj | |
{ | |
class MainClass | |
{ |
This file contains 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
import java.util.concurrent.atomic.AtomicReference | |
import java.util.concurrent.CountDownLatch | |
import scala.concurrent.Future | |
import scala.concurrent.ExecutionContext | |
import ExecutionContext.Implicits.global | |
object TxMapTest { | |
/* | |
* Example Usage | |
* We want to show two threads working with the same data source having both of their effects succeed |
This file contains 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 GenericCache[A[_,_], B, C](instance: A[B,C], getf: B=>C, putf: (B,C)=>Unit) { | |
def retrieve(b: B) = getf(b) | |
def insert(b: B, c: C) = putf(b,c) | |
} | |
//Notice how neither cache implementations have to even be aware of the existnace of the typeclass. much more flexible than inheritance | |
class FastCache[A,B] { | |
private var m = Map[A,B]() //excuse mutability for illustration purposes | |
def add(a: A, b: B): Unit = { | |
m = m + (a->b) |
This file contains 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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace XSharpx { | |
public struct Writer<A, B> | |
{ | |
public readonly A a; | |
public readonly B b; | |
public readonly Semigroup<A> semigroup; |
This file contains 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
import scalaz._ | |
import Scalaz._ | |
import scalaz.Free._ | |
//calling a.run(0) blows up obviously due to stack issues | |
val a = (0 to 10000).map(ii => State[Int,Int](i => (i,ii)) ).foldLeft( State[Int,Int](i => (i,0)) )( (s,a) => s.flatMap(i => a.map(ii => (ii+i) ))) | |
//calling b.run(0) blows up, not stack safe. | |
val b = (0 to 10000).map(ii => StateT[Free.Trampoline,Int,Int](i => Trampoline.done((i,ii))) ).foldLeft( StateT[Free.Trampoline, Int,Int](i => Trampoline.done((i,0))) )( (s,a) => s.flatMap(i => a.map(ii => (ii+i) ))) |
This file contains 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
import scala.concurrent.Future | |
import scalaz._ | |
import Scalaz._ | |
import scala.concurrent.ExecutionContext.Implicits.global | |
val fa = OptionT( Future { 1.some } )//Returns an OptionT[Future,Int] | |
val fb = OptionT( Future { 2.some } ) | |
//we don't need to nest for comprehensions since the OptionT unwraps the Option | |
// automatically in addition to whatever monad it's abstracting over | |
for { |
OlderNewer