다음을 통해 공유


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

지정된 함수가 true를 반환하는 첫째 요소의 인덱스를 반환합니다.

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

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

// Signature:
Seq.findIndex : ('T -> bool) -> seq<'T> -> int

// Usage:
Seq.findIndex predicate source

매개 변수

  • predicate
    형식: 'T -> bool

    특정 요소의 인덱스가 반환되어야 하는지 여부를 테스트하는 함수입니다.

  • source
    형식: seq<'T>

    입력 시퀀스입니다.

예외

Exception

조건

ArgumentNullException

입력 시퀀스가 null인 경우 throw됩니다.

KeyNotFoundException

조건자에 의해 평가될 때 true를 반환하는 요소가 없는 경우 throw됩니다.

반환 값

지정된 함수가 true를 반환하는 첫째 요소의 인덱스입니다.

설명

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

예제

다음 코드 예제에서는 Seq.findIndex을 사용하는 방법을 보여 줍니다.

let seqA = [| 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 = Seq.find (fun elem -> isPerfectSquare elem && isPerfectCube elem) seqA
let index = Seq.findIndex (fun elem -> isPerfectSquare elem && isPerfectCube elem) seqA
printfn "The first element that is both a square and a cube is %d and its index is %d." element index

Output

  

플랫폼

Windows Windows 서버 2012, Windows Server 2008 R2, Windows 7, 8

버전 정보

F# 코어 라이브러리 버전

지원: 2.0, 4.0, 노트북

참고 항목

참조

Collections.Seq 모듈(F#)

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