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
implicit val myEnumDecodeJson: DecodeJson[MyEnum] = DecodeJson{hCursor => | |
hCursor.focus match { | |
case `myEnumValue1Json` => DecodeResult.ok(MyEnumValue1) | |
case `myEnumValue2Json` => DecodeResult.ok(MyEnumValue2) | |
case _ => DecodeResult.fail("Expected MyEnum.", hCursor.history) | |
} | |
} |
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
-- In this case it would be in theory be possible to create a single thunk for "ab" if pointless was partially applied as so: | |
-- pointless 1 2 | |
-- The resulting Int -> Int method would then only have to evaluate ab once because otherwise it never changes. | |
-- The obvious possibility this could cause would be caching very large intermediate representations that would otherwise be | |
-- garbage collected. | |
pointless :: Int -> Int -> Int -> Int | |
pointless a b c = | |
let ab = a + b | |
in ab + c |
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
sean@Tower:~/workspace/rwst-wiring$ .cabal-sandbox/bin/doctest -isrc Control.Monad.Trans.Reader.Wiring | |
### Failure in src/Control/Monad/Trans/Reader/Wiring.hs:17: expression `:{ | |
let composedResult = do | |
result1 <- promoteReader $ request1 "1" | |
result2 <- promoteReader $ request2 "2" | |
return [result1, result2] :: ReaderT (Database1, Database2) IO [String] | |
:}' | |
expected: >>> runReaderT composedResult (Database1, Database2) | |
["User1", "User2"] | |
but got: |
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
-- To run this file you just need the ghc application from the Haskell Platform bundle | |
-- With that on a command line run the following (assuming the code is in Monads.hs): | |
-- ghc Monads.hs && ./Monads | |
-- Imports needed for later: | |
import System.IO | |
-- So pretty much every language has this concept: | |
-- doThingA(); | |
-- doThingB(); | |
-- If that wasn't hugely clear, it was the concept of calling one bit of code |
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
scala> val list = List(1.right[String], "Fail".left[Int], 3.right[String]) | |
list: List[scalaz.\/[String,Int]] = List(\/-(1), -\/(Fail), \/-(3)) | |
scala> list.sequenceU | |
res1: scalaz.\/[String,List[Int]] = -\/(Fail) | |
scala> val list = List(1.right[String], 2.right[String], 3.right[String]) | |
list: List[scalaz.\/[String,Int]] = List(\/-(1), \/-(2), \/-(3)) | |
scala> list.sequenceU |
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
path("metric" / Segment) { location => | |
val _uri = "http://<url>/api/crowd_api/metric?mode=Select&location=" + location | |
val _result = scala.io.Source.fromURL(_uri).mkString | |
val _xml = XML.loadString(_result) | |
val _crowd = _xml \\ "crowd" | |
case class Crowd(c_location: String, c_metric: String) | |
implicit def CrowdCodecJson: CodecJson[Crowd] = casecodec2(Crowd.apply, Crowd.unapply)("c_location", "c_metric") | |
val crowd_ = _crowd.map{ n => |
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._,Scalaz._,scalaz.effect._,OptionT._,Kleisli._ | |
type OptionTIO[+X] = OptionT[IO, X] | |
val reader1: ReaderT[Option, Int, String] = kleisli[Option, Int, String](n => n.toString.some) | |
val reader2: ReaderT[IO, Int, String] = kleisli[IO, Int, String](n => IO((n * 2).toString)) | |
val convertedReader1: ReaderT[OptionTIO, Int, String] = reader1.mapK[OptionTIO, String](opt => optionT(IO(opt))) | |
val convertedReader2: ReaderT[OptionTIO, Int, String] = reader2.mapK[OptionTIO, String](io => io.liftM[OptionT]) |
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 Control.Parallel | |
nfib :: Int -> Int | |
nfib = (map fib [0 ..] !!) | |
where fib 0 = 0 | |
fib 1 = 1 | |
fib n = par n1 (pseq n2 (n1 + n2)) | |
where n2 = nfib (n-2) | |
n1 = nfib (n-1) |
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 doThing[M[+_]: Monad, T, U, V] | |
(actionOne: () => ReaderT[M, T, Unit], | |
actionTwo: () => ReaderT[M, T, Unit], | |
actionThree: () => ReaderT[M, T, Unit], | |
actionFour: () => ReaderT[M, (T, U), Unit], | |
actionFive: () => ReaderT[M, T, Unit, | |
actionSix: () => ReaderT[M, V, Unit]) | |
(): ReaderT[M, (T, U, V), Unit] = { | |
for { | |
_ <- actionOne().localFrom[(T, U, V)] |
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
[error] (myproject/compile:compile) scala.reflect.internal.FatalError: class Universe does not have a member Quasiquote |