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
module Database where | |
import System.Random (getStdRandom, randomR) | |
import Project | |
getBudget :: ProjectId -> IO Budget | |
getBudget _ = do | |
income <- Money <$> getStdRandom (randomR (0, 10000)) | |
expenditure <- Money <$> getStdRandom (randomR (0, 10000)) | |
pure Budget { budgetIncome = income, budgetExpenditure = expenditure} |
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
-- from | |
-- https://www.youtube.com/watch?v=lxjIUWGMUqE | |
-- Haskell at Work - Validation with Smart Constructors | |
module SerialNumber | |
( SerialNumber | |
, ValidataionError(..) | |
, makeSerialNumber | |
, renderSerialNumber | |
) where |
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 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) |
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 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.) |
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
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 |
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
/** | |
* 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 |
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
/** | |
* @see https://www.youtube.com/watch?v=UjSQlUjuZWQ | |
* @see https://bartoszmilewski.com/2019/07/03/programming-with-universal-constructions/ | |
*/ | |
object BartozUniversalsConstructions { | |
// C | |
// / | \ | |
// / | \ | |
// / | \ |
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 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 | |
*/ |
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 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. |
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 hangman | |
import java.io.IOException | |
//import cats._ | |
import cats.{Apply, Functor, Monad} | |
import cats.implicits._ | |
import scalaz.zio._ | |
import scalaz.zio.console._ |