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
/** | |
* wrap a container purely (ie: with no effects) in a FlowState and transform it in a ResT | |
* @param container the container to wrap | |
* @param transformer the function to transform the container into a Res[U] | |
* @tparam M the container | |
* @tparam T the type inside the container | |
* @tparam U the type inside the resulting Res | |
* @return the Res[U] returned by the transformer wrapped purely in a FlowState and transformed by a ResT | |
*/ | |
private def wrapPure[M[_], T, U](container: M[T])(transformer: M[T] => Res[U]): ResT[FlowState, U] = { |
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
/** | |
* transform a type purely (no effects) into a ReqRespState[T]. | |
* note that a ReqRespState[T] is the same as a scalaz.State[ReqRespData, T] | |
* @param t the type to transform | |
* @tparam T the type | |
* @return the resulting ReqRespState[T] | |
*/ | |
protected def reqRespStatePure[T](t: T): ReqRespState[T] = { | |
t.pure[ReqRespState] | |
} |
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 Probably.A.Lot.More.Shit | |
//this is how you construct a State manually by the way | |
val myState: State[ReqRespData, Res[String]] = state { d: ReqRespData => | |
val myRes: Res[String] = ValueRes("hello world") | |
(d, myRes) | |
} | |
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
//build an extension to any State[ReqRespData, Res[Something]] | |
trait StateResW[T] { | |
protected def state: State[ReqRespData, Res[T]] | |
def mapRes[U](f: T => U): State[ReqRespData, Res[U]] = state.map { res: Res[T] => | |
res match { | |
case ValueRes(t) => ValueRes(f(t)) | |
case other => other: Res[U] | |
} | |
} | |
} |
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 scalamachine.core._ | |
import scalamachine.scalaz._ | |
val myState: State[ReqRespData, Res[String]] = state { d: ReqRespData => | |
val myRes: Res[String] = ValueRes("hello world") | |
(d, myRes) | |
} |
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 TaggedTypes { | |
sealed trait TaggedType[T] { | |
def underlying: T | |
override def toString = underlying.toString | |
} | |
//implicitly extract the primitive value from a TaggedType[T] | |
implicit def underlying[T](w: TaggedType[T]): T = { | |
w.underlying | |
} | |
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 net.liftweb.json._ | |
import net.liftweb.json.scalaz.JsonScalaz._ | |
def json[T](serialize: T => JValue, deserialize: JValue => Result[T]): JSON[T] = new JSON[T] { | |
def write(t: T) = serialize(t) | |
def read(jval: JValue): Result[T] = deserialize(jval) | |
} |
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 liftscalaz { | |
import scalaz._ | |
type ScalazFailure = Failure | |
def ScalazFailure[E, S](e: E): ScalazValidation[E, S] = Failure[E, S](e) | |
type ScalazSuccess = Success | |
def ScalazSuccess[E, S](s: S): ScalazValidation[E, S] = Success[E, S](s) | |
type ScalazValidation = Validation |
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._ | |
//here we say that the default value for List[String] is "hello" :: "world" :: Nil | |
implicit val listZero = new Zero[List[String]] = { | |
override lazy val zero = List("hello", "world") | |
} | |
//scalaz uses Zero in its unary ~ operator on Option | |
val mbListString = none[List[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
trait PolyFunc[Out] { | |
def apply[In]: In => Out | |
} | |
sealed trait HList { | |
} | |
//the end of an HList | |
sealed class HNil extends HList { |