Array.find<'T> 함수(F#)

지정된 함수가 true를 반환하는 첫째 요소를 반환합니다. 이러한 요소가 없으면 KeyNotFoundException이 발생합니다.

네임스페이스/모듈 경로: Microsoft.FSharp.Collections.Array

어셈블리: FSharp.Core(FSharp.Core.dll)

// Signature:
Array.find : ('T -> bool) -> 'T [] -> 'T

// Usage:
Array.find predicate array

매개 변수

  • predicate
    형식: 'T -> bool

    입력 요소를 테스트하는 함수입니다.

  • array
    형식: 'T []

    입력 배열입니다.

예외

Exception

Condition

KeyNotFoundException

predicate가 어떤 요소에 대해서도 true를 반환하지 않으면 throw됩니다.

반환 값

predicate이 true를 반환하는 첫째 요소입니다.

설명

컴파일된 어셈블리에서 이 함수의 이름은 Find입니다. F# 이외의 언어에서 함수에 액세스하거나 리플렉션을 통해 함수에 액세스하는 경우 이 이름을 사용합니다.

예제

다음 예제에서는 정사각형이면서 큐브인 1보다 큰 첫 번째 정수를 식별하도록 Array.findArray.findIndex의 사용을 보여줍니다.

let arrayA = [| 2 .. 100 |]
let delta = 1.0e-10
let isPerfectSquare (x:int) =
    let y = sqrt (float x)
    abs(y - round y) < delta
let isPerfectCube (x:int) =
    let y = System.Math.Pow(float x, 1.0/3.0)
    abs(y - round y) < delta
let element = Array.find (fun elem -> isPerfectSquare elem && isPerfectCube elem) arrayA
let index = Array.findIndex (fun elem -> isPerfectSquare elem && isPerfectCube elem) arrayA
printfn "The first element that is both a square and a cube is %d and its index is %d." element index
  

플랫폼

Windows 7, Windows Vista SP2, Windows XP SP3, Windows XP x64 SP2, Windows Server 2008 R2, Windows Server 2008 SP2, Windows Server 2003 SP2

버전 정보

F# 런타임

지원되는 버전: 2.0, 4.0

Silverlight

지원되는 버전: 3

참고 항목

참조

Collections.Array 모듈(F#)

Microsoft.FSharp.Collections 네임스페이스(F#)

Array.findIndex<'T> 함수(F#)