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
def OtoS[A](o: Option[A => A]): State[A,A] = | |
o match { | |
case Some(f) => State[A,A](a => { | |
val na = f(a) | |
(na,na) | |
}) | |
case None => State[A,A](a => (a,a)) | |
} |
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
def sepSeq[A, B, F[_], G[_]](g: G[EitherT[F, A, B]])(implicit F: Monad[F], G: Foldable[G], M: MonadPlus[G]): EitherT[F, A, (G[A],G[B])] = | |
EitherT(G.foldRight(g, F.point((M.empty[A],M.empty[B])))( (a, l) => | |
for { | |
tup <- l | |
e <- a.run | |
} yield | |
e.fold(le => (M.plus(M.point(le),tup._1), tup._2), re => (tup._1, M.plus(M.point(re), tup._2))) | |
).map(_.right[A]) | |
) |
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
val eitherK = EitherT[({ type l[a] = Kleisli[Option, String, a]})#l, String, Int]( Kleisli((s:String) => (1.right[String]).some ) ) | |
class MyBlah[A, B, F[_], G[_]](value: G[EitherT[F, A, B]]) | |
new MyBlah(List(eitherK)) |
This file has been truncated, but you can view the full file.
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
<?xml version='1.0' encoding='UTF-8'?> | |
<?xml-stylesheet type='text/xsl' href='reportXMLtoHTML.xsl'?> | |
<classycle title='scalaz-core_2.11-7.1.0.jar' date='2015-02-09'> | |
<cycles> | |
<cycle name="scalaz.NaturalTransformation et al." size="2" longestWalk="0" girth="2" radius="1" diameter="1" bestFragmentSize="1"> | |
<classes> | |
<classRef name="scalaz.NaturalTransformation" eccentricity="1" maximumFragmentSize="1"/> | |
<classRef name="scalaz.NaturalTransformations" eccentricity="1" maximumFragmentSize="1"/> | |
</classes> | |
<centerClasses> |
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
object Test { | |
trait BlahConfig[A <: BlahConfig[A]] { | |
val server: Int | |
def updateCache(l: List[Int]): A | |
} | |
def doBlahStuff[A <: BlahConfig[A]](i: Int) = State[A, Int]( c => (c.updateCache(List(i)), c.server) ) | |
trait FooConfig[A <: FooConfig[A]] { | |
def password: String |
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
object Test { | |
import scalaz.{Lens,State} | |
case class BlahConfig(server: Int, l: List[Int]) | |
def doStuff(i: Int) = State[BlahConfig,Int]( c => (c.copy(l = i :: c.l), c.server) ) | |
case class FooConfig(val password: String) | |
def doSomeStuff(i: Int) = State[FooConfig, String](c =>(c, c.password)) | |
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 Shift(start: DateTime, end: DateTime) | |
case class Coverage(time: DateTime, amount: Int) | |
def findCoverages(increment: Int, shifts: List[Shift]): List[Coverage] = { | |
shifts.map(s => generateDates(increment, s.start, s.end)) | |
.flatten //Going from List[List[DateTime]] to List[DateTime] | |
.groupBy(dt => dt) //just grouping by date, groupBy always returns a Map[Key, List[Value]] | |
.map(kv => Coverage(kv._1, kv._2.size)) //when mapping over a Map/Dictionary, the parameter is a tuple, with _1 being the key and _2 being the value | |
.toList |
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 stackotalk | |
import scalaz._ | |
import Scalaz._ | |
import org.joda.time._ | |
object Dates { | |
def generateDates(sd: DateTime, ed: DateTime): List[DateTime] = { | |
if (sd isBefore ed) | |
sd :: generateDates(sd.plusDays(1), ed) |
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
object StateApply { | |
import scalaz._ | |
implicit def applyState[F[_], A](implicit F: Applicative[F], S: Semigroup[A]): Applicative[({ type l[a] = StateT[F, A, a]})#l] = new Applicative[({ type l[a] = StateT[F, A, a]})#l] { | |
def point[B](b: => B): StateT[F, A, B] = StateT[F, A, B]((a:A) => F.point((a,b))) | |
def ap[B, C](fa: => StateT[F, A, B])(f: => StateT[F, A, B => C]): StateT[F, A, C] = { | |
StateT[F, A, C]((s: A) => { | |
val sa = fa.run(s) | |
val sb = f.run(s) |
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
[core] λ test:console | |
[info] Starting scala interpreter... | |
[info] | |
Loading... | |
Welcome to the Ammonite Repl 0.4.7 | |
(Scala 2.10.4 Java 1.8.0_60) | |
@ "hello" | |
java.lang.NullPointerException | |
com.sqality.scct.IO$class.relativePath(IO.scala:74) | |
com.sqality.scct.IO$.relativePath(IO.scala:6) |