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
function calc(users) { | |
return _.reduce(_.map(users, (user) => { | |
return _.reduce(_.map(user.puzzles, (puzzle) => { | |
return { | |
puzzleId: puzzle.puzzleId, | |
errors: _.reduce(puzzle.moves, (acc, move) => { | |
if (move.isValid) return acc; | |
else { | |
var fromState = _.get(move, 'fromState'); | |
return _.merge({}, acc, { [fromState]: _.concat((_.get(acc, fromState) || []), move.toState) }); |
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
// RegistrationFormValidator.validateForm(form) returns Either[ValidationError, ValidRegistration] | |
// the expected return type of our HttpService[F] creator is F[Response[F]], so here we use .bimap | |
// and friends to finagle our validated form into that type. | |
val service: HttpService[F] = { | |
HttpService[F] { | |
case req @ POST -> Root / "users" => | |
req.decode[RegistrationForm] { form => | |
RegistrationFormValidator.validateForm(form).bimap(error => registrationFailed(error), | |
user => insertRegistration(User(UUID.randomUUID, user.email, user.password.bcrypt)) |
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
// given a List[Int], e.g. List(1, 50, 250, 250, 50, 6), find all the pairs of numbers which sum to 500 | |
def pairsOfSumOfN(ns: List[Int], n: Int): List[(Int, Int)] = | |
ns.zipWithIndex.map(pair => ns.zipWithIndex.filter(_._2 != pair._2).map(_._1).zipWithIndex.map(second => (pair._1, second._1))).flatMap(a => a.filter(b => n == (b._1 + b._2))) | |
pairsOfSumOfN(List(1, 50, 250, 250, 50, 6), 500) // returns List((250, 250), (250, 250))! (can we dedupe this list by using indexes? you bet!) |
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 cats.effect.IO | |
import cats.Monad | |
import api.AirlinesService | |
import api.ProfilesService | |
import api.TripService | |
/* | |
* ok, let's say we have our services, but instead of Promises, this is Scala, | |
* so our services return IOs of responses as such: |
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
package me.omega | |
import cats.effect.{IOApp, IO, ExitCode} | |
import cats.Monad | |
import cats.data.Kleisli | |
import cats.syntax.all._ | |
object Main extends IOApp { | |
override def run(args: List[String]): IO[ExitCode] = new App[IO].run.as(ExitCode.success) // `.as` is sugar for `.map[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
name := "hola-kevin" | |
version := "0.1" | |
scalaVersion := "2.12.7" | |
scalacOptions += "-Ypartial-unification" | |
libraryDependencies += "org.typelevel" %% "cats-core" % "1.4.0" | |
libraryDependencies += "org.typelevel" %% "cats-effect" % "1.0.0" |
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
package LetThereBeEcho | |
trait Terminal[C[_]] { | |
def read: C[String] | |
def write(t: String): C[Unit] | |
} | |
trait Execution[C[_]] { | |
def doAndThen[A, B](c: C[A])(f: A => C[B]): C[B] | |
def create[B](b: B): C[B] |
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 bucketConfig = new BucketNotificationConfiguration() | |
bucketConfig.setConfigurations(existingConfig) | |
s3.setBucketNotificationConfiguration( | |
new SetBucketNotificationConfigurationRequest(config.bucket, bucketConfig) | |
) |
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
{-# LANGUAGE NoImplicitPrelude #-} | |
module Main where | |
import Protolude | |
import qualified Data.Text as T | |
calculateThing :: ExceptT Text IO Text | |
calculateThing = do | |
print $ T.pack "log" |