Skip to content

Instantly share code, notes, and snippets.

View Jacoby6000's full-sized avatar

Jacob Barber Jacoby6000

  • Plano, TX
View GitHub Profile
class MoreMonadErrorOps[F[_], A](val fa: F[A]) extends AnyVal {
def liftError[G[_], C, D, E](nt: F ~> G)(raiseErr: C => G[E])(implicit G: MonadError[G, E], ev: A <~< Validation[C, D]): G[D] =
for {
a <- nt(fa)
validation = ev(a)
result <- validation.fold(raiseErr(_).flatMap(G.raiseError[D]), G.pure(_))
} yield result
def index(id: UUIDFor[File]): F[ValidationNel[StoreTreeError, List[DatabaseFile]]] = {
for {
maybeDbFile <- mToF(songDb.getDirectory(id))
dbFile <- maybeDbFile.getOrElseF(F.raiseError[Directory](IndexTargetNotFoundInDatabase(id)))
maybeFileSystemTree <-nToF(fileTree(apiKeyToPath(dbFile.apiKey.value), None))
fileSystemTree <- maybeFileSystemTree.getOrElseF(F.raiseError[FileTree](IndexTargetNotFoundInFileSystem(dbFile.apiKey.value)))
storedTree <- mToF(storeTree(fileSystemTree, None))
} yield storedTree
package scalaz.effect
import java.util.concurrent.TimeUnit
import org.openjdk.jmh.annotations._
import scala.concurrent.Await
import IOBenchmarks._
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
public class wot.DoIt {
public scala.collection.immutable.List<scala.Option<java.lang.Object>> foo(scala.collection.immutable.List<scala.Tuple2<java.lang.Object, scala.Option<java.lang.Object>>>);
Code:
0: aload_1
1: invokedynamic #39, 0 // InvokeDynamic #0:apply:()Lscala/Function1;
6: getstatic #45 // Field scala/collection/immutable/List$.MODULE$:Lscala/collection/immutable/List$;
9: invokevirtual #49 // Method scala/collection/immutable/List$.canBuildFrom:()Lscala/collection/generic/CanBuildFrom;
12: invokevirtual #55 // Method scala/collection/immutable/List.map:(Lscala/Function1;Lscala/collection/generic/CanBuildFrom;)Ljava/lang/Object;
15: checkcast #51 // class scala/collection/immutable/List
18: areturn
public final class wot.DoIt$$anonfun$foo$1$$anonfun$apply$1 extends scala.runtime.AbstractFunction1$mcII$sp implements scala.Serializable {
public static final long serialVersionUID;
public final int apply(int);
Code:
0: aload_0
1: iload_1
2: invokevirtual #20 // Method apply$mcII$sp:(I)I
5: ireturn
scala> val x: In = 10
x: ScalaScript.In = 10 with properties Map()
scala> x.foo = "bar"
x.foo: Any = bar
scala> x
res4: ScalaScript.In = 10 with properties Map(foo -> bar with properties Map())
import scala.reflect.ClassTag
import scala.reflect.runtime.universe._
import scala.language.dynamics
import scala.language.implicitConversions
import scala.reflect.api.{Mirror => SRMirror, TypeCreator, Universe}
import scala.Predef.{implicitly, locally, any2stringadd => _}
class ScalaScripter(val a: Any) extends Dynamic {
import ScalaScript.{enable => toScalaScript, disable => unScalaScript}
sealed trait Pipeline[A, B, C] {
def compose[D, E, F](that: Pipeline[D, E, F]): Compose[A, B, C, D, E] = Compose(this, that)
}
case class Compose[A, B, C, D, E](p1: Pipeline[A, B, C], p2: Pipeline[C, D, E]) extends Pipeline[A, (B, D), E]
case class Run[A, B, C](f: A => B => C) extends Pipeline[A, B, C]
type F1 = (A1, P1) => A2
type F2 = (A2, P2) => A3
type F3 = (A3, P3) => A4
def foo(a1: A1): P1 => P2 => P3 => A4 = p1: P1 => p2: P2 => p3: P3 => F3(F2(F1(a1, p1), p2), p3)
(=<<) f (OptionalT fMaybeA) =
OptionalT (
fMaybeA >>= \o ->
case o of
Full x -> runOptionalT (f x)
Empty -> pure Empty)