Skip to content

Instantly share code, notes, and snippets.

View tomatophobia's full-sized avatar
:octocat:

Youngseo Choi tomatophobia

:octocat:
View GitHub Profile
package Speed
case class World(containers: Map[Symbol, Container]) {
def getAmount(key: Symbol): Double = {
containers(key).group.amountPerContainer
}
def addWater(key: Symbol, amount: Double): World = {
val group = containers(key).group
val members = group.members
package speed2
case class World(containers: Map[Symbol, Container]) {
def getAmount(key: Symbol): (World, Double) = {
val newWorld = updateGroup(key)
(newWorld, newWorld.containers(key).amount)
}
def updateGroup(key: Symbol): World = {
@annotation.tailrec
package speed2
import cats.data.State
case class World(containers: Map[Symbol, Container])
case class Container(amount: Double, next: Symbol)
object Container {
def apply(name: Symbol): Container = Container(0.0, name)
}
class BoundedSet2[T] {
val data: util.LinkedList[T] = new util.LinkedList[T]()
var capacity: Int = 0
def BoundedSet(capacity: Int) {
this.capacity = capacity;
}
def add(elem: T) {
// 일반적인 프로그래밍 언어
const x = "key"
const y = db(x) // db에 접속해서 데이터 가져온다. 부수 효과 발생
const z = http(y) // http 요청을 보내 데이터를 가져온다. 마찬가지로 부수 효과 발생
console.log(z) // 콘솔에 출력 당연히 부수효과 발생
// 함수형 프로그래밍
const x = "key"
const f = (a) => db(a) // db에 접속해서 데이터를 가져오는 "함수". 실행하지 않았으므로 부수효과는 발생하지 않음.
const g = (b) => http(b) // 위와 같이 부수효과는 발생하지 않고 함수만 생성.
const h = (c) => console.log(c) // 위와 같음.
h(g(f(x))) // 모든 함수를 합성한 후 실행한다. 모든 부수효과가 이 지점에서 발생한다.
const x = "key"
const f = (a) => () => db(a)
const g = (b) => () => http(b)
const h = (c) => () => console.log(c)
h(g(f(x)())())()
type IO<T> = () => T
const x: string = "key"
const f: string => IO<string> = (a) => () => db(a)
const g: string => IO<string> = (b) => () => http(b)
const h: string => IO<string> = (c) => () => console.log(c)
h(g(f(x)())())()
implementation "com.linecorp.armeria:armeria:1.23.1"
implementation "com.linecorp.armeria:armeria-spring-boot3-starter:1.23.1"
implementation "com.linecorp.armeria:armeria-tomcat10:1.23.1"
import com.linecorp.armeria.server.tomcat.TomcatService;
import com.linecorp.armeria.spring.ArmeriaServerConfigurator;
import org.apache.catalina.connector.Connector;
import org.springframework.boot.web.embedded.tomcat.TomcatWebServer;
import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class WebConfiguration {