Skip to content

Instantly share code, notes, and snippets.

View gustavofranke's full-sized avatar

Gustavo Franke gustavofranke

View GitHub Profile
@gustavofranke
gustavofranke / take-home.hs
Last active January 26, 2020 23:23
my solutions to pchiusano's amazing gist
import Control.Monad
import Control.Applicative
-- | from https://gist.github.com/pchiusano/bf06bd751395e1a6d09794b38f093787
-- 1. Sum up a `[Int]`, using explicit recursion. (nuts and bolts)
sum' :: [Int] -> Int
sum' [] = 0
sum' (i:is) = i + (sum' is)
import System.Random
import Data.List
-- | https://wiki.haskell.org/99_questions/1_to_10
-- Problem 1
-- (*) Find the last element of a list.
-- (Note that the Lisp transcription of this problem is incorrect.)
module FizzBuzz where
data Foo = Fizz | Buzz | FizzBuzz | Neither Int
instance Show Foo where
show Fizz = "Fizz"
show Buzz = "Buzz"
show FizzBuzz = "FizzBuzz"
show (Neither int) = show int
/**
* Write a program that prints the numbers from 1 to 100.
* But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz".
* For numbers which are multiples of both three and five print "FizzBuzz".
*/
object FizzBuzzApp extends App {
sealed trait Foo
case object Fizz extends Foo
case object Buzz extends Foo
case object FizzBuzz extends Foo
/**
* @see https://www.youtube.com/watch?v=UjSQlUjuZWQ
* @see https://bartoszmilewski.com/2019/07/03/programming-with-universal-constructions/
*/
object BartozUniversalsConstructions {
// C
// / | \
// / | \
// / | \
import scala.io.StdIn.readLine
import scala.util.Try
/**
* Trivial code, anyone would understand what's going on here.
* But requirements change, and we never know in which direction the change will be.
*
* The code has a procedural and interactive nature, how would you go about this in another, let alone better way?
* Still, it has bugs; so let's find them and solve them first
*/
package tasks.option
import org.scalatest.FunSuite
/**
* show some scala stuff that I found weird when I started this journey
*
* I'll use scala test as a vehicle,
* but this is not a talk about writing tests, so the tests themselves will be a little repetitive.
* I'll be using a very basic subset of the library, the library has lots of features.
@gustavofranke
gustavofranke / hangman-zio.scala
Last active November 25, 2018 16:18
John de Goes' purely functional hangman
package hangman
import java.io.IOException
//import cats._
import cats.{Apply, Functor, Monad}
import cats.implicits._
import scalaz.zio._
import scalaz.zio.console._
@gustavofranke
gustavofranke / fpmax.scala
Last active February 13, 2020 14:25
John de Goes' Fpmax in a granular way that helps me to visualise the sequence refactoring steps, I stopped when the code became testable
package fpmax
import scala.io.StdIn.readLine
import scala.util.Try
object App0 extends App {
def main(): Unit = {
println("What is your name?")
val name = readLine()
val toEnglish = Map((0, 4) -> "four", (1, 3) -> "thirty", (2, 2) -> "two hundreds", (3, 1) -> "one thousand")
def intToEnglish(a: Int): String = a.toString.toList
.map { _.toString.toInt }
.reverse.zipWithIndex.reverse
.map { t => toEnglish(t.swap) }
.mkString(" ")
intToEnglish(4) // res0: String = four
intToEnglish(34) // res1: String = thirty four