#스칼라 stable identifier
def f(x: Int, y: Int) = x match { case `y` => ... }
Now, the pattern matches the y
parameter of the enclosing function f
. That is, the match succeeds only if the x
argument and the y
argument of f
are equal
def getFieldValueFromJson(jsonString: String, fieldName: String): Option[Json] = {
jsonString.fromJson[Json] match {
case Right(Json.Obj(fields)) => fields.collectFirst { case (`fieldName`, v) => v }
case _ => None
}
}
// find + map을 collectFirst로 바꿀 수 있다.
배운 것
from. sean
내가 변경하고 싶은 부분을 빠르게 찾는 법
- 우선 특정 함수가 수행할 것이라고 기대하는 것이 명확해야 함
- 함수 스코프 단위로 파악해서 모르는 부분을 추상화해야 함
- 만약 해당 스코프가 아니라면 빠르게 함수를 호출하는 부분으로 넘어가기
- 또는 함수가 여러 곳에서 호출된다면 순서대로 탐색하기
chatGPT에게 관련 context 설명하는 방법 리팩토링 하려고 할 때 무지성으로 복붙하지 말고 원본 코드가 어떤 의미를 가졌는 지 파악한 후 복붙할 곳을 탐색한다