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
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 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 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 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 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 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 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.Concurrent.Lifted | |
import Control.Monad.Base | |
import Data.IORef.Lifted | |
import Data.Traversable | |
import qualified Data.HashSet as S | |
import qualified Data.HashMap.Strict as M | |
import System.IO.Unsafe | |
import Debug.Trace | |
:set prompt "ghci> " |
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
proxyCall :: (Typeable a) => String -> a -> Q Exp | |
proxyCall serviceName toProxy = do | |
let parameterCount n a' = case (typeRepArgs a') of | |
[x, xs] -> if tyConName $ typeRepTyCon x == "IO" then n else parameterCount (n + 1) xs | |
_ -> undefined | |
let noOfParameters = parameterCount 0 $ typeOf toProxy | |
fieldNames <- traverse (\n -> mkName ("a" ++ (show n))) [1..noOfParameters] | |
valueName <- fmap fromJust $ lookupValueName serviceName | |
return [p| $(valueName) resource $(fieldNames) = Pool.withResource pool (\(ThriftConnection _ client) -> $(toProxy) client $(fieldNames)) |] |
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
renderRoute :: HasRep as => S.Path as -> HVectElim as H.AttributeValue | |
renderRoute path = | |
let curryIt :: (HVect as -> H.AttributeValue) -> HVectElim as H.AttributeValue | |
curryIt = hVectCurry | |
uncurryIt :: HVectElim as Text -> HVect as -> Text | |
uncurryIt = hVectUncurry | |
renderIt :: S.Path as -> HVectElim as Text | |
renderIt = S.renderRoute | |
in curryIt $ fmap H.textValue $ uncurryIt $ renderIt path |
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
type AppRWS a = RWST ReaderEnv () () IO a | |
type SpockTApp a = SpockT (RWST ReaderEnv () () IO) a |
OlderNewer