Publish to my blog (weekly)

    • 그 예외 항목이 먼지 알려주는 함수가 isDefinedAt 입니다.
    • PartialFunction 은 아래와 같이 만들며 자동으로 isDefinedAt 이 만들어지는게 특징입니다.
    • [Int, Int] 는 인자로 Int 리턴값으로 Int 를 말합니다.
    • Partial Function 을 이해하는 쉬운 방법은, 일반 FunctionTotal Function 으로 이해하면 된다. 즉, 일반 Function 이 주어진 인자에 대해 모든 값을 취한다면, Partial Function 은 주어진 타입에 대해서 특정 값만 취할 수 있다. Scala School 의 원문을 첨부하면
    • A function works for every argument of the defined type. In other words, a function defined as (Int) => String takes any Int and returns a String. 
        A Partial Function is only defined for certain values of the defined type. A Partial Function (Int) => String might not accept every Int.
    • 처음엔 caseFunction 을 만든다고 했지만, 사실 PartialFunction 을 정의한다.
    • mapfilterFunction 을 받지만, PartialFunctionFunction 의 subtype 이므로 파라미터로 넘겨줄 수 있다.
    • One is for writing anonymous functions that accept tuples and work on their components, as you did with f1. An example would be the function you pass to the foreach or map method on a Map, e.g. Map(1 -> 2, 3 -> 4) map { case (k, v) => k + v }.
    • The second is for writing an anonymous function that does a match on its sole parameter. Your f2 is doing this, but not in any useful way. An example would be the anonymous function passed to collect, e.g. List(1, -2, 3) collect { case x if x > 0 => -x }.

Posted from Diigo. The rest of my favorite links are here.

댓글

이 블로그의 인기 게시물

Publish to my blog (weekly)

Publish to my blog (weekly)