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
val five = 5 | |
five match { | |
case v if v > 5 => ??? | |
case v if v == 5 => ??? | |
case v if v < 5 => ??? | |
} | |
// more practical example | |
final case class FeeInquiry(user: UserId, amount: BigDecimal, currency: Currency) | |
val requestedFee: Option[FeeInquiry] = ??? |
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
final case class Human(name: String, age: Int) | |
trait SimpleCrud[F[_]] { | |
val simpleCrudService: SimpleCrud.Service[F] | |
} | |
object SimpleCrud { | |
trait Service[F[_]] { | |
def add: F[Unit] | |
def find(name: Name): F[Option[Human]] | |
} | |
} |
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 cats.Applicative | |
import cats.effect.concurrent.Ref | |
import cats.implicits._ | |
import cats.effect._ | |
class InMemorySimpleCrud[F[_]: Applicative](ref: Ref[F, Map[String, Human]]) | |
extends SimpleCrud.Service[F] { | |
override def add(human: Human): F[Unit] = | |
ref.update(_.updated(human.name, human)) | |
override def find(name: String): F[Option[Human]] = |
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 java.math.BigInteger | |
def gcd(left: Long, right: Long): Long = BigInteger.valueOf(left).gcd(BigInteger.valueOf(right)).longValue |
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
// porivided width * height | |
// calculate the number of empty cells | |
// ex) [ ][ ][/] | |
// [ ][/][ ] | |
//. [/][ ][ ] | |
// | |
// gcd : https://gist.github.com/emmettna/702d972126d381dcceb8d8122ba7893c | |
def calcEmptyCells(width: Int, heght: Int): Int = width + heght - (gcd(width, heght)) |
OlderNewer