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 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 |
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 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 |
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 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) | |
| } |
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
| 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) { |
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
| // 함수형 프로그래밍 | |
| const x = "key" | |
| const f = (a) => db(a) // db에 접속해서 데이터를 가져오는 "함수". 실행하지 않았으므로 부수효과는 발생하지 않음. | |
| const g = (b) => http(b) // 위와 같이 부수효과는 발생하지 않고 함수만 생성. | |
| const h = (c) => console.log(c) // 위와 같음. | |
| h(g(f(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
| // 일반적인 프로그래밍 언어 | |
| const x = "key" | |
| const y = db(x) // db에 접속해서 데이터 가져온다. 부수 효과 발생 | |
| const z = http(y) // http 요청을 보내 데이터를 가져온다. 마찬가지로 부수 효과 발생 | |
| console.log(z) // 콘솔에 출력 당연히 부수효과 발생 |
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
| const x = "key" | |
| const f = (a) => () => db(a) | |
| const g = (b) => () => http(b) | |
| const h = (c) => () => console.log(c) | |
| h(g(f(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
| 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)())())() |
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 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 { |
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 com.linecorp.armeria.common.HttpResponse; | |
| import com.linecorp.armeria.common.HttpStatus; | |
| import com.linecorp.armeria.server.annotation.*; | |
| import more.practice.armeriaspring.model.Todo; | |
| import more.practice.armeriaspring.service.TodoService; | |
| import org.springframework.beans.factory.annotation.Autowired; | |
| import org.springframework.stereotype.Controller; | |
| import java.util.List; |
OlderNewer