Skip to content

Instantly share code, notes, and snippets.

Avatar

Gustavo Franke gustavofranke

View GitHub Profile
View bootcamp2.scala
package option
import org.scalatest.funsuite.AnyFunSuite
/**
* show some scala language features that, if you come from other languages, they might be unknown to you.
*
* Like last week, we'll play with the REPL, then turn our findings into tests.
*
* I'll use scala-test to automate this process,
View Cube.hs
module Geometry.Cube
( volume
, area
) where
import qualified Geometry.Cuboid as Cuboid
volume :: Float -> Float
volume side = Cuboid.volume side side side
View OverloadedStrings.hs
Data.Time> :t "foo"
"foo" :: [Char]
Data.Time> :set -XOverloadedStrings
Data.Time> :t "foo" "foo" :: Data.String.IsString p => p
View repl-time.hs
-- stack repl --package <package-name>
-- stack repl --package time
> import Data.Time
Data.Time> getCurrentTime
2020-10-17 15:03:15.521782 UTC
Data.Time> utctDay <$> getCurrentTime
2020-10-17
Data.Time> today <- utctDay <$> getCurrentTime
Data.Time> today
View cipher.scala
package cipher
def lowers(xs: String): Int =
xs.filter(x => x >= 'a' && x <= 'z').length
def count(x: Char, xs: String): Int =
xs.toList.filter(x0 => x == x0).length
def positions[A](x: A, xs: List[A]): List[Int] =
for
View diy-zio.scala
package playground
// https://www.youtube.com/watch?v=xpz4rf1RS8c
// 01. functional effects
// Console - Model 1
sealed trait Console1 { self =>
def +(that: Console1): Console1 = Sequence1(self, that)
}
final case class Print1(line: String) extends Console1
final case class Sequence1(first: Console1, second: Console1) extends Console1
@gustavofranke
gustavofranke / exercises.hs
Last active Apr 11, 2020
first chapters sample code
View exercises.hs
-- 1.7Exercises
-- 1.Give another possible calculation for the result of double (double 2).
double x = x + x
another = (double . double) 2
-- 2.Show that sum [x] = x for any number x.
ex2 :: (Eq a, Num a) => a -> Bool
ex2 x = sum [x] == x
View write-you-a-scheme.hs
module Main where
import Control.Monad
import Control.Monad.Except
import System.Environment
import Text.ParserCombinators.Parsec hiding (spaces)
main :: IO ()
main = do
args <- getArgs
evaled <- return $ liftM show $ readExpr (args !! 0) >>= eval
@gustavofranke
gustavofranke / Database.hs
Last active Feb 6, 2020
Domain Modelling with Haskell: Data Structures - from https://www.youtube.com/watch?v=pe6S5skZwNE
View Database.hs
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}
View SerialNumber.hs
-- from
-- https://www.youtube.com/watch?v=lxjIUWGMUqE
-- Haskell at Work - Validation with Smart Constructors
module SerialNumber
( SerialNumber
, ValidataionError(..)
, makeSerialNumber
, renderSerialNumber
) where