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 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 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 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 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 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 has been truncated, but you can view the full file.
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
<?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 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 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 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 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 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 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 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 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 { |
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.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 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
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; |