Skip to content

Instantly share code, notes, and snippets.

View joshuakfarrar's full-sized avatar
💻
EitherT[IO, Throwable, Human]

Joshua K. Farrar joshuakfarrar

💻
EitherT[IO, Throwable, Human]
View GitHub Profile
{-
State monad things, but in Haskell.
I am but a humble FP noob.
-}
module Main where
@joshuakfarrar
joshuakfarrar / Main.scala
Last active July 6, 2018 22:26
Implement FP in Scala exercise 6.11 using Cats' State Monad.
import cats.data.State
sealed trait Input
case object Coin extends Input
case object Turn extends Input
case class Machine(locked: Boolean, candies: Int, coins: Int)
object Main extends App {
val insertCoin: State[Machine, (Boolean, Int)] = State(machine => {
/* interop */
[@bs.val] [@bs.scope "Math"] external random : unit => float = "random";
[@bs.val] [@bs.scope "Math"] external floor : float => int = "floor";
let random = (max: float): int => {
floor(random() *. max);
};
let x = (n: int): option('float) => {
switch (n) {
| 0 => None
[%bs.raw {|require('./App.css')|}];
[@bs.module] external logo : string = "./logo.svg";
type action = Hello | Goodbye | Whatever;
type state = {
greeting: string
};
package me.sent1nel
import cats.effect.IO
import io.circe.{Json, Encoder}
import org.http4s.HttpService
import org.http4s.dsl.Http4sDsl
import org.http4s.server.blaze.BlazeBuilder
import org.http4s.util.StreamApp
import org.http4s.circe._
package me.sent1nel
sealed trait Stream[+A] {
def headOption: Option[A] = this match {
case Empty => None
case Cons(h, t) => Some(h())
}
// 5.1
def toList: List[A] = {
sealed trait Tree[+A]
case class Leaf[A](value: A) extends Tree[A]
case class Branch[A](left: Tree[A], right: Tree[A]) extends Tree[A]
object Tree {
// 3.29, FP in Scala
def identity[A](a: A): A = a // I combinator
def constant[A,B](a: A)(b: B): A = a // K combinator
def map[A,B](t: Tree[A])(f: A => B): Tree[B] =
package me.sent1nel;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
// https://javalin.io/
import io.javalin.Javalin;
import io.javalin.Handler;
// actor started
// First: Actor[akka://testSystem/user/first-actor#-477064136]
// >>> Press ENTER to exit <<<
// Second: Actor[akka://testSystem/user/first-actor/second-actor#1443434381]
// sub-actor started
// sub-actor stopped
// actor stopped
package com.lightbend.akka.sample
object Solution {
def main(args: Array[String]) {
val sc = new java.util.Scanner (System.in);
var n = sc.nextInt();
var a = Array.ofDim[Int](n,n);
for(a_i <- 0 to n-1) {
for(a_j <- 0 to n-1){
a(a_i)(a_j) = sc.nextInt();
}