View bootcamp2.scala
This file contains 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 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
This file contains 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 Geometry.Cube | |
( volume | |
, area | |
) where | |
import qualified Geometry.Cuboid as Cuboid | |
volume :: Float -> Float | |
volume side = Cuboid.volume side side side | |
View OverloadedStrings.hs
This file contains 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
Data.Time> :t "foo" | |
"foo" :: [Char] | |
Data.Time> :set -XOverloadedStrings | |
Data.Time> :t "foo" "foo" :: Data.String.IsString p => p |
View repl-time.hs
This file contains 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
-- 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
This file contains 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 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
This file contains 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 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 |
View exercises.hs
This file contains 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
-- 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
This file contains 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 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 |
View Database.hs
This file contains 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} |
View SerialNumber.hs
This file contains 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 |
NewerOlder