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
object Fintech5 { | |
data class ValidationError(val message: String) | |
data class CreatePortfolio(val userId: String, val amount: Double) | |
data class ChangePortfolio(val userId: String, val stock: String, val quantity: Int) | |
interface Validator<T> { | |
fun T.check(): EitherNel<ValidationError, T> | |
} |
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 com.contextReceivers | |
import kotlin.random.Random | |
fun String.sarcastic(): String = | |
asIterable().joinToString("") { | |
if (Random.nextBoolean()) it.uppercase() else it.lowercase() | |
} | |
fun printTransformedGreeting(transform: String.() -> Unit) { |
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 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, |
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 Geometry.Cube | |
( volume | |
, area | |
) where | |
import qualified Geometry.Cuboid as Cuboid | |
volume :: Float -> Float | |
volume side = Cuboid.volume side side side | |
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
Data.Time> :t "foo" | |
"foo" :: [Char] | |
Data.Time> :set -XOverloadedStrings | |
Data.Time> :t "foo" "foo" :: Data.String.IsString p => p |
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
-- 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 |
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 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 |
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 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 |
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
-- 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 |
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 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 |
NewerOlder