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
| import _root_.org.springframework.transaction.support.{TransactionCallback, TransactionTemplate} | |
| import _root_.org.springframework.transaction.TransactionStatus | |
| object TransactionUtils { | |
| def inTransaction[T](tt:TransactionTemplate)(block: =>T):T = | |
| tt.execute(new TransactionCallback[T]() { | |
| override def doInTransaction(status:TransactionStatus) = block | |
| }) | |
| } |
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
| import java.util.concurrent.ExecutorService | |
| import java.util.concurrent.atomic.AtomicReference | |
| import akka.dispatch.ExecutorBasedEventDrivenDispatcher | |
| import akka.dispatch.Dispatchers | |
| import akka.dispatch.MailboxType | |
| abstract class ExecutorDispatcher( | |
| name: String, | |
| throughput: Int = Dispatchers.THROUGHPUT, |
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
| import scalaz._ | |
| import Scalaz._ | |
| implicit def OptionMonoid[A : Monoid]: Monoid[Option[A]] = new Monoid[Option[A]] { | |
| def append(s1: Option[A], s2: => Option[A]) = for (x <- s1; y <- s2) yield implicitly[Monoid[A]].append(x, y) | |
| val zero = Some(implicitly[Monoid[A]].zero) | |
| } | |
| val optionalNums = (1 to 10) map { some(_) } | |
| optionalNums.asMA.sum.println |
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
| class IteratorW[A](itr: Iterator[A]) { | |
| def groupWhen(fn: A => Boolean): Iterator[Seq[A]] = new Iterator[Seq[A]] { | |
| private val bitr = itr.buffered | |
| override def hasNext = bitr.hasNext | |
| override def next = { | |
| val xs = collection.mutable.ListBuffer(bitr.next) | |
| while (bitr.hasNext && !fn(bitr.head)) xs += bitr.next | |
| xs.toSeq | |
| } | |
| } |
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
| Caused by: java.lang.reflect.MalformedParameterizedTypeException | |
| at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.validateConstructorArguments(ParameterizedTypeImpl.java:60) | |
| at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.<init>(ParameterizedTypeImpl.java:53) | |
| at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.make(ParameterizedTypeImpl.java:95) | |
| at sun.reflect.generics.factory.CoreReflectionFactory.makeParameterizedType(CoreReflectionFactory.java:104) | |
| at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:140) | |
| at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49) | |
| at sun.reflect.generics.repository.ConstructorRepository.getParameterTypes(ConstructorRepository.java:94) | |
| at java.lang.reflect.Method.getGenericParameterTypes(Method.java:300) | |
| at java.beans.FeatureDescriptor.getParameterTypes(FeatureDescriptor.java:385) |
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 RWS extends App { | |
| trait Pointed[P[_]] { | |
| def point[A](a: A): P[A] | |
| } | |
| trait PointedFunctor[PF[_]] extends Pointed[PF] with Functor[PF] | |
| implicit def listIsMonoid[A]: Monoid[List[A]] = new Monoid[List[A]] { | |
| def id: List[A] = Nil |
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
| def enumLines[F[_]](r: => BufferedReader)(implicit MO: MonadPartialOrder[F, IO]): EnumeratorT[IoExceptionOr[String], F] = | |
| new EnumeratorT[IoExceptionOr[String], F] { | |
| import MO._ | |
| import EnumeratorT._ | |
| lazy val reader = r | |
| def apply[A] = (s: StepT[IoExceptionOr[String], F, A]) => | |
| s.mapContOr({ | |
| k => { | |
| val i = IoExceptionOr(reader.readLine) | |
| if (i exists { _ != null }) k(Input(i)) >>== apply[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
| val m: Map[Int, Either[Int, String]] = ... | |
| val rights = m.collect { case (k, Right(v)) => k -> v } | |
| val lefts = m.collect { case (k, Left(v)) => k -> v } | |
| val m: Map[Int, Int \/ String] = ... | |
| val rights = m.collect { case (k, v) if v.isRight => k -> v.toOption.get } | |
| val lefts = m.collect { case (k, v) if v.isLeft => k -> v.swap.toOption.get } | |
| val n: ValidationNEL[String, Int] = ... |
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
| import scalaz._ | |
| import Scalaz._ | |
| import scalaz.iteratee._ | |
| import EnumeratorT._ | |
| def counter[A, F[+_]: Pointed] = | |
| IterateeT.fold[A, F, Int](0) { (acc: Int, a: A) => acc + 1 } | |
| def count[A, F[+_]: Monad](e: EnumeratorT[A, F]) = | |
| (counter[A, F] &= e).run |
OlderNewer