분류 전체보기
-
opaque typescala/scala3 2024. 3. 22. 14:21
object Company { opaque type Name = String object Name { def apply(s: String): Name = s } extension (name: Name) def length: Int = name.length // inside: Name String def fullName(first: Name, second: Name): Name = { first.concat(second) // String 의 method 를 사용 가능 } } @main def Main(): Unit = { import Company.* // Outside, Name & String are NOT related val first: Name = "First" // NOT allowed, Er..
-
Function value signature for generics, context functionsscala/scala3 2024. 3. 22. 01:01
import scala.concurrent.duration.* import scala.concurrent.{Await, ExecutionContext, Future} def processOption[A](opt: Option[A]): String = opt match { case Some(v) => s"[$v]" case None => "[]" } @main def main(): Unit = { /** Generics in functions */ val processOptionFunction: [A] => Option[A] => String = { [A] => (opt: Option[A]) => processOption(opt) } processOptionFunction(Some(1)) /** Conte..
-
typeclassscala/scala3 2024. 3. 22. 00:21
공식문서: https://docs.scala-lang.org/scala3/reference/contextual/type-classes.html#(import 된 given 의 내부에 들어있는 extension method 는 자동으로 꺼내져 적용된다?)예제1case class Rect(width: Double, height: Double)case class Circle(radius: Double)trait Shape[A] { extension (a: A) { def area(): Double }}object Shape { // given listLast[T](using ...): Last[List[T]] = ... 형태로 사용도 가능 (generics 경우) given Shape[Rect] ..
-
method 이름은 같은데 param, return 타입을 다르게 구현하기scala/basic 2024. 3. 7. 17:06
case class GoogleRaw(content: String, crawlId: String) case class NaverRaw(content: String) case class GoogleParsed(sections: Seq[String], crawlId: String) case class NaverParsed(sections: Seq[String]) trait Cralwer { type Raw type Parsed def fetch(url: String): Raw def parse(raw: Raw): Parsed def save(raw: Raw, parsed: Parsed): Int } object GoogleCrawler extends Cralwer { type Raw = GoogleRaw t..
-
conda commandspython/conda 2024. 2. 14. 14:29
miniconda install가이드 문서: https://docs.conda.io/projects/conda/en/latest/user-guide/install/linux.htmlubuntu 에 설치하기: https://docs.anaconda.com/free/miniconda/#quick-command-line-install 기본 명령어env 생성 / 삭제conda env listconda init bash # .bashrc 환경 설정conda create -y -n kjm_env conda-pack python=3.8.15conda activate kjm_envconda deactivateconda env remove -n kjm_env env 생성하는 또 다른 방법 -..
-
Command 모음git 2024. 2. 8. 18:41
작업 했던 모든 것을 되돌릴 때 git reset git checkout . 특정 파일을 tracking 에서 제외할 때 git rm --cached .idea/misc.xml 기존 repo 를 복제해 새로운 repo 를 만들 때 remote repo A 를 remote repo B 로 복제해 보자 1. 새로운 remote repo B 를 만듬. (파일을 1개 이상 생성하자) 2. 기존 remote repo A 를 local 로 clone (local_REPO) 함 3. local repo (local_REPO) 의 remote 정보를 수정해 remote repo B 로 변경함 (git remote ... ) 4. local repo (local_REPO) 와 remote repo B 를 연결하기 위해 ..
-
python MixInpython/응용 2024. 1. 31. 17:07
scala 의 trait mixin 과 비슷한 것 같다. 상속을 통해 공통으로 사용할 member, method 를 클래스에 추가함? 예제 코드 class ToDictMixin: def to_dict(self): return {key: value for key, value in self.__dict__.items()} class MyClass(ToDictMixin, BaseClass): pass 다중 상속일 경우 Q: Under multiple inheritances, if two parent classes have the same methods or attributes, what will happen? A: If two parent classes have the same method or attribu..