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 main | |
import "fmt" | |
type ( | |
employee interface { | |
yearContribution() float32 | |
baseSalary() int | |
toString() string | |
} |
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
(ns example | |
(:require [clojure.spec :as s])) | |
;; Spec section. It's not needed for the solution, but provides | |
;; documentation and can generate tests. | |
(def employee-types #{:office-worker :field-agent}) | |
(s/def ::type employee-types) | |
(s/def ::years (s/int-in 0 100)) | |
(s/def ::name string?) |
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
sealed abstract class Employee(val name: String, years: Int, baseSalary: BigDecimal) { | |
//abstract method | |
def yearsContribution(): BigDecimal | |
//do the same logic with different data and sub-logic in each subclass | |
def salary(): BigDecimal = baseSalary + yearsContribution() | |
override def toString: String = s"My name is $name and I've been working here for $years years." | |
} |
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
root_package: org.tindalos.principle | |
checks: | |
layering: | |
layers: [infrastructure, app, domain] | |
violation_threshold: 0 | |
third_party_restrictions: | |
allowed_libraries: |
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
trait AccountService { | |
def credit(userId: Int, amount: Int): Reader[Context, Unit] | |
def debit(userId: Int, amount: Int): Reader[Context, Unit] | |
} | |
val service: AccountService = ??? | |
val transfer: Reader[Context, Unit] = for { | |
_ ← service.credit(1, 10) | |
_ ← service.debit(2, 10) |
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
case class Reader[R, A](run: R ⇒ A) { | |
def map[B](f: A ⇒ B): Reader[R, B] = Reader(r ⇒ f(run(r))) | |
def flatMap[B](f: A ⇒ Reader[R, B]): Reader[R, B] = Reader(r ⇒ f(run(r)).run(r)) | |
} | |
object UserService { | |
def notifyUser(user: User): Reader[Context, Unit] = Reader { context ⇒ | |
context.userRepository.find(user.id) match { | |
case Some(foundUser) ⇒ context.notificationService.notifyUserAboutSth(foundUser) | |
case None ⇒ println("No user found!") |
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
case class Context(userRepository: UserRepository, notificationService: NotificationService) | |
object UserService { | |
def notifyUser(userId: Int): Context ⇒ Unit = context ⇒ | |
context.userRepository.find(userId) match { | |
case Some(foundUser) ⇒ context.notificationService.notifyUserAboutSth(foundUser) | |
case None ⇒ println("No user found!") | |
} | |
} |
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
case class User(id: Int) | |
trait NotificationService { | |
def notifyUserAboutSth(user: User): Unit | |
} | |
trait UserRepository { | |
def find(id: Int): Option[User] | |
} |
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 org.bluecollar.scalaz | |
import scalaz.Scalaz._ | |
import scalaz._ | |
object StateMonadExamples extends App { | |
//Domain and test values | |
sealed trait Input | |
case object Coin extends Input |
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
[" " | |
" ## " | |
" ## " | |
" ## " | |
" ## " | |
" "] |