Set up build.sbt with the following:
//TODO add cats
scalaVersion := "2.12.4"
libraryDependencies += "org.scalaz" %% "scalaz-core" % "7.2.18"
Alright I was trying to find that article but it has way more details then I remember. Here’s what we basically do: | |
We have a App Monad or “Context” | |
newtype App a = App {unApp :: ReaderT Environment IO a} | |
So you can see the IO thing in there but you’ll notice there’s something called ReaderT and Environment. I’ll get to those. | |
Now when you mess around with Haskell you might use functions in IO e.g. | |
foo :: IO () |
{-# LANGUAGE DeriveDataTypeable #-} | |
import qualified Data.Data as D | |
import Data.Data (Data) | |
data Gurren = Gurren { | |
owner :: String | |
, spiralPower :: Natural | |
} deriving (Data) | |
let properties = D.constrFields . head . D.dataTypeConstrs $ D.dataTypeOf (undefined :: Gurren) |
import { default as faker } from 'faker' | |
import { fold, none, Option, some } from 'fp-ts/lib/Option' | |
import { pipe } from 'fp-ts/lib/pipeable' | |
import { keys } from 'fp-ts/lib/Record' | |
import { evalState, State } from 'fp-ts/lib/State' | |
import * as t from 'io-ts' | |
import { NumberFromString } from 'io-ts-types/lib/NumberFromString' | |
import { Moment } from 'moment' | |
// TODO don't use lodash |
import {Firestore} from "@google-cloud/firestore" | |
import { firestore as firestoreAdmin } from 'firebase-admin' | |
import {foldMap} from 'fp-ts/lib/Array' | |
import {pipe} from 'fp-ts/lib/pipeable' | |
import {monoidSum} from 'fp-ts/lib/Monoid' | |
import {flatMap, some as exists} from 'lodash' | |
import * as io from 'io-ts' | |
import { Timestamp } from '@google-cloud/firestore' |
object ParEitherNonEmpty { | |
import cats.data.NonEmptyList.catsDataSemigroupForNonEmptyList | |
import cats.data.{NonEmptyList, Validated} | |
new Parallel[Either[NonEmptyList[_], ?]] { | |
override type F[v] = Validated[NonEmptyList[_], v] | |
override def applicative: Applicative[Validated[NonEmptyList[_], *]] = { | |
Validated.catsDataApplicativeErrorForValidated[NonEmptyList[_]](catsDataSemigroupForNonEmptyList) | |
} |
import scala.collection.mutable | |
class TrieNode(var children: mutable.Map[Char, TrieNode] = mutable.Map()) { | |
// Inserts into current Trie | |
def insert(c: Char): TrieNode = { | |
children.get(c).getOrElse({ | |
children.put(c, new TrieNode()) | |
this | |
} | |
) |
val s = %%pbpaste | |
s.out.string.split("\n").filter(_.contains("$")).map(_.split("\\$")(1)).map(_.toFloat).sum |
import scala.language.experimental.macros | |
//WIP does not function | |
final class lookerUpper extends scala.annotation.StaticAnnotation { | |
import lookerUpper._ | |
/** | |
* @param annottees list of untyped annottees | |
* @return | |
*/ |
addCommandAlias("partestDebugOn", """set javaOptions in test in IntegrationTest += "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5008" """) | |
addCommandAlias("partestDebugOff", """set javaOptions in test in IntegrationTest -= "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5008" """) | |
addCommandAlias("replDebugOn_212", """set javaOptions in run in replJlineEmbedded += "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5008" """) | |
addCommandAlias("replDebugOff_212", """set javaOptions in run in replJlineEmbedded -= "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5008" """) | |
addCommandAlias("replDebugOn_213", """set javaOptions in run in replFrontend += "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5008" """) | |
addCommandAlias("replDebugOff_213", """set javaOptions in run in replFrontend -= "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5008" """) |