배열(F#)

배열은 모두 동일한 형식의 연속된 데이터 요소의 고정 크기, 0부터 시작하는 변경 가능한 컬렉션입니다.

배열 만들기

여러 가지 방법으로 배열을 만들 수 있습니다. 다음 예제와 같이 세미콜론 간에 [| 연속된 값을 나열하고 |] 세미콜론으로 구분하여 작은 배열을 만들 수 있습니다.

let array1 = [| 1; 2; 3 |]

각 요소를 별도의 줄에 배치할 수도 있습니다. 이 경우 세미콜론 구분 기호는 선택 사항입니다.

let array1 =
    [|
        1
        2
        3
     |]

배열 요소의 형식은 사용된 리터럴에서 유추되며 일관성이 있어야 합니다.

// This is an array of 3 integers.
let array1 = [| 1; 2; 3 |]
// This is an array of a tuple of 3 integers.
let array2 = [| 1, 2, 3 |]

다음 코드에서는 3.0이 부동 소수점이고 1과 2가 정수이므로 오류가 발생합니다.

// Causes an error. The 3.0 (float) cannot be converted to integer implicitly.
// let array3 = [| 1; 2; 3.0 |]

다음 코드는 튜플이고 3 정수이므로 오류가 1,2 발생합니다.

// Causes an error too. The 3 (integer) cannot be converted to tuple implicitly.
// let array4 = [| 1, 2; 3 |]

시퀀스 식을 사용하여 배열을 만들 수도 있습니다. 다음은 1에서 10까지 정수의 제곱 배열을 만드는 예제입니다.

let array3 = [| for i in 1 .. 10 -> i * i |]

모든 요소가 0 Array.zeroCreate으로 초기화되는 배열을 만들려면 .

let arrayOfTenZeroes : int array = Array.zeroCreate 10

액세스 요소

대괄호([])를 사용하여 배열 요소에 액세스할 수 있습니다. 원래 점 구문(.[index])은 계속 지원되지만 F# 6.0에서는 더 이상 권장되지 않습니다.

array1[0]

배열 인덱스는 0부터 시작합니다.

또한 배열의 하위 범위를 지정할 수 있는 조각 표기법을 사용하여 배열 요소에 액세스할 수도 있습니다. 조각 표기법의 예는 다음과 같습니다.

// Accesses elements from 0 to 2.

array1[0..2]

// Accesses elements from the beginning of the array to 2.

array1[..2]

// Accesses elements from 2 to the end of the array.

array1[2..]

조각 표기법을 사용하면 배열의 새 복사본이 만들어집니다.

배열 형식 및 모듈

모든 F# 배열의 형식은 .NET Framework 형식 System.Array입니다. 따라서 F# 배열은 .에서 사용할 수 있는 System.Array모든 기능을 지원합니다.

이 모듈Array 1차원 배열에 대한 작업을 지원합니다. 모듈은 Array2D각각 2, Array4DArray3D3, 4차원 배열에 대한 작업을 지원하는 함수를 포함합니다. 를 사용하여 System.Array순위가 4보다 큰 배열을 만들 수 있습니다.

단순 함수

Array.get 요소를 가져옵니다. Array.length 는 배열의 길이를 제공합니다. Array.set 는 요소를 지정된 값으로 설정합니다. 다음 코드 예제에서는 이러한 함수의 사용을 보여 줍니다.

let array1 = Array.create 10 ""
for i in 0 .. array1.Length - 1 do
    Array.set array1 i (i.ToString())
for i in 0 .. array1.Length - 1 do
    printf "%s " (Array.get array1 i)

출력은 다음과 같습니다.

0 1 2 3 4 5 6 7 8 9

배열을 만드는 함수

여러 함수는 기존 배열을 요구하지 않고 배열을 만듭니다. Array.empty 는 요소를 포함하지 않는 새 배열을 만듭니다. Array.create 는 지정된 크기의 배열을 만들고 모든 요소를 제공된 값으로 설정합니다. Array.init 는 요소를 생성하는 차원 및 함수가 지정된 배열을 만듭니다. Array.zeroCreate 는 모든 요소가 배열 형식에 대한 0 값으로 초기화되는 배열을 만듭니다. 다음 코드에서는 이러한 함수를 보여 줍니다.

let myEmptyArray = Array.empty
printfn "Length of empty array: %d" myEmptyArray.Length



printfn "Array of floats set to 5.0: %A" (Array.create 10 5.0)


printfn "Array of squares: %A" (Array.init 10 (fun index -> index * index))

let (myZeroArray : float array) = Array.zeroCreate 10

출력은 다음과 같습니다.

Length of empty array: 0
Area of floats set to 5.0: [|5.0; 5.0; 5.0; 5.0; 5.0; 5.0; 5.0; 5.0; 5.0; 5.0|]
Array of squares: [|0; 1; 4; 9; 16; 25; 36; 49; 64; 81|]

Array.copy 는 기존 배열에서 복사되는 요소를 포함하는 새 배열을 만듭니다. 복사본은 단순 복사본입니다. 즉, 요소 형식이 참조 형식인 경우 참조만 복사되고 기본 개체는 복사되지 않습니다. 다음 코드 예제에서는 그 구체적인 방법을 보여 줍니다.

open System.Text

let firstArray : StringBuilder array = Array.init 3 (fun index -> new StringBuilder(""))
let secondArray = Array.copy firstArray
// Reset an element of the first array to a new value.
firstArray[0] <- new StringBuilder("Test1")
// Change an element of the first array.
firstArray[1].Insert(0, "Test2") |> ignore
printfn "%A" firstArray
printfn "%A" secondArray

이전 코드의 출력은 다음과 같습니다.

[|Test1; Test2; |]
[|; Test2; |]

새 요소를 만드는 작업은 참조를 덮어쓰지만 여전히 있는 빈 문자열에 대한 원래 참조 firstArray 에는 영향을 주지 않으므로 문자열 Test1 은 첫 번째 배열에secondArray만 나타납니다. Test2 형식에 대한 작업이 두 배열 Insert 에서 참조되는 기본 System.Text.StringBuilder 개체에 System.Text.StringBuilder 영향을 주므로 문자열이 두 배열에 모두 나타납니다.

Array.sub 는 배열의 하위 범위에서 새 배열을 생성합니다. 시작 인덱스 및 길이를 제공하여 하위 정렬을 지정합니다. 다음 코드는 Array.sub의 사용법을 보여줍니다.

let a1 = [| 0 .. 99 |]
let a2 = Array.sub a1 5 10
printfn "%A" a2

출력은 하위 배열이 요소 5에서 시작되고 10개의 요소를 포함하는 것을 보여 줍니다.

[|5; 6; 7; 8; 9; 10; 11; 12; 13; 14|]

Array.append 는 두 개의 기존 배열을 결합하여 새 배열을 만듭니다.

다음 코드에서는 Array.append를 보여 줍니다.

printfn "%A" (Array.append [| 1; 2; 3|] [| 4; 5; 6|])

이전 코드의 출력은 다음과 같습니다.

[|1; 2; 3; 4; 5; 6|]

Array.choose 는 새 배열에 포함할 배열의 요소를 선택합니다. 다음 코드에서는 .를 보여 줍니다.Array.choose 배열의 요소 형식은 옵션 형식에서 반환된 값의 형식과 일치할 필요가 없습니다. 이 예제에서 요소 형식은 int 부동 소수점 숫자로 다항식 함수 elem*elem - 1의 결과입니다.

printfn "%A" (Array.choose (fun elem -> if elem % 2 = 0 then
                                            Some(float (elem*elem - 1))
                                        else
                                            None) [| 1 .. 10 |])

이전 코드의 출력은 다음과 같습니다.

[|3.0; 15.0; 35.0; 63.0; 99.0|]

Array.collect 는 기존 배열의 각 배열 요소에 대해 지정된 함수를 실행한 다음 함수에서 생성된 요소를 수집하고 새 배열로 결합합니다. 다음 코드에서는 .를 보여 줍니다.Array.collect

printfn "%A" (Array.collect (fun elem -> [| 0 .. elem |]) [| 1; 5; 10|])

이전 코드의 출력은 다음과 같습니다.

[|0; 1; 0; 1; 2; 3; 4; 5; 0; 1; 2; 3; 4; 5; 6; 7; 8; 9; 10|]

Array.concat 는 배열 시퀀스를 사용하여 단일 배열로 결합합니다. 다음 코드에서는 .를 보여 줍니다.Array.concat

Array.concat [ [|0..3|] ; [|4|] ]
//output [|0; 1; 2; 3; 4|]

Array.concat [| [|0..3|] ; [|4|] |]
//output [|0; 1; 2; 3; 4|]

Array.filter 는 부울 조건 함수를 사용하고 조건이 true인 입력 배열에서 해당 요소만 포함하는 새 배열을 생성합니다. 다음 코드에서는 .를 보여 줍니다.Array.filter

printfn "%A" (Array.filter (fun elem -> elem % 2 = 0) [| 1 .. 10|])

이전 코드의 출력은 다음과 같습니다.

[|2; 4; 6; 8; 10|]

Array.rev 는 기존 배열의 순서를 반대로 하여 새 배열을 생성합니다. 다음 코드에서는 .를 보여 줍니다.Array.rev

let stringReverse (s: string) =
    System.String(Array.rev (s.ToCharArray()))

printfn "%A" (stringReverse("!dlrow olleH"))

이전 코드의 출력은 다음과 같습니다.

"Hello world!"

다음 예제와 같이 파이프라인 연산자()|>를 사용하여 배열을 변환하는 배열 모듈의 함수를 쉽게 결합할 수 있습니다.

[| 1 .. 10 |]
|> Array.filter (fun elem -> elem % 2 = 0)
|> Array.choose (fun elem -> if (elem <> 8) then Some(elem*elem) else None)
|> Array.rev
|> printfn "%A"

출력은 다음과 같습니다.

[|100; 36; 16; 4|]

다차원 배열

다차원 배열을 만들 수 있지만 다차원 배열 리터럴을 작성하는 구문은 없습니다. 연산 array2D 자를 사용하여 배열 요소 시퀀스의 시퀀스에서 배열을 만듭니다. 시퀀스는 배열 또는 목록 리터럴일 수 있습니다. 예를 들어 다음 코드는 2차원 배열을 만듭니다.

let my2DArray = array2D [ [ 1; 0]; [0; 1] ]

이 함수 Array2D.init 를 사용하여 두 차원의 배열을 초기화할 수도 있으며, 3차원과 4차원 배열에 유사한 함수를 사용할 수 있습니다. 이러한 함수는 요소를 만드는 데 사용되는 함수를 사용합니다. 함수를 지정하는 대신 초기 값으로 설정된 요소를 포함하는 2차원 배열을 만들려면 최대 4개의 차원 배열에도 사용할 수 있는 함수를 사용합니다 Array2D.create . 다음 코드 예제에서는 먼저 원하는 요소를 포함하는 배열 배열을 만든 다음 Array2D.init 원하는 2차원 배열을 생성하는 방법을 보여 줍니다.

let arrayOfArrays = [| [| 1.0; 0.0 |]; [|0.0; 1.0 |] |]
let twoDimensionalArray = Array2D.init 2 2 (fun i j -> arrayOfArrays[i][j])

배열 인덱싱 및 조각화 구문은 순위 4까지의 배열에 대해 지원됩니다. 여러 차원에서 인덱스를 지정하는 경우 다음 코드 예제와 같이 쉼표로 인덱스를 구분합니다.

twoDimensionalArray[0, 1] <- 1.0

2차원 배열의 형식은 (예int[,]: , double[,])로 <type>[,] 작성되고, 3차원 배열의 형식은 더 높은 차원의 배열에 대해 등으로 <type>[,,]작성됩니다.

1차원 배열에 사용할 수 있는 함수의 하위 집합만 다차원 배열에 사용할 수 있습니다.

배열 조각화 및 다차원 배열

2차원 배열(행렬)에서 범위를 지정하고 와일드카드(*) 문자를 사용하여 전체 행 또는 열을 지정하여 하위 행렬을 추출할 수 있습니다.

// Get rows 1 to N from an NxM matrix (returns a matrix):
matrix[1.., *]

// Get rows 1 to 3 from a matrix (returns a matrix):
matrix[1..3, *]

// Get columns 1 to 3 from a matrix (returns a matrix):
matrix[*, 1..3]

// Get a 3x3 submatrix:
matrix[1..3, 1..3]

다차원 배열을 동일하거나 낮은 차원의 하위 배열로 분해할 수 있습니다. 예를 들어 단일 행 또는 열을 지정하여 행렬에서 벡터를 가져올 수 있습니다.

// Get row 3 from a matrix as a vector:
matrix[3, *]

// Get column 3 from a matrix as a vector:
matrix[*, 3]

요소 액세스 연산자와 오버로드된 GetSlice 메서드를 구현하는 형식에 대해 이 조각화 구문을 사용할 수 있습니다. 예를 들어 다음 코드는 F# 2D 배열을 래핑하고, Item 속성을 구현하여 배열 인덱싱을 지원하고, 세 가지 버전을 GetSlice구현하는 행렬 형식을 만듭니다. 이 코드를 행렬 형식에 대한 템플릿으로 사용할 수 있는 경우 이 섹션에서 설명하는 모든 조각화 작업을 사용할 수 있습니다.

type Matrix<'T>(N: int, M: int) =
    let internalArray = Array2D.zeroCreate<'T> N M

    member this.Item
        with get(a: int, b: int) = internalArray[a, b]
        and set(a: int, b: int) (value:'T) = internalArray[a, b] <- value

    member this.GetSlice(rowStart: int option, rowFinish : int option, colStart: int option, colFinish : int option) =
        let rowStart =
            match rowStart with
            | Some(v) -> v
            | None -> 0
        let rowFinish =
            match rowFinish with
            | Some(v) -> v
            | None -> internalArray.GetLength(0) - 1
        let colStart =
            match colStart with
            | Some(v) -> v
            | None -> 0
        let colFinish =
            match colFinish with
            | Some(v) -> v
            | None -> internalArray.GetLength(1) - 1
        internalArray[rowStart..rowFinish, colStart..colFinish]

    member this.GetSlice(row: int, colStart: int option, colFinish: int option) =
        let colStart =
            match colStart with
            | Some(v) -> v
            | None -> 0
        let colFinish =
            match colFinish with
            | Some(v) -> v
            | None -> internalArray.GetLength(1) - 1
        internalArray[row, colStart..colFinish]

    member this.GetSlice(rowStart: int option, rowFinish: int option, col: int) =
        let rowStart =
            match rowStart with
            | Some(v) -> v
            | None -> 0
        let rowFinish =
            match rowFinish with
            | Some(v) -> v
            | None -> internalArray.GetLength(0) - 1
        internalArray[rowStart..rowFinish, col]

module test =
    let generateTestMatrix x y =
        let matrix = new Matrix<float>(3, 3)
        for i in 0..2 do
            for j in 0..2 do
                matrix[i, j] <- float(i) * x - float(j) * y
        matrix

    let test1 = generateTestMatrix 2.3 1.1
    let submatrix = test1[0..1, 0..1]
    printfn $"{submatrix}"

    let firstRow = test1[0,*]
    let secondRow = test1[1,*]
    let firstCol = test1[*,0]
    printfn $"{firstCol}"

배열의 부울 함수

각각 하나 또는 두 개의 배열에서 함수 Array.existsArray.exists2 테스트 요소입니다. 이러한 함수는 테스트 함수를 사용하고 조건을 충족하는 요소(또는 요소 쌍Array.exists2)가 있는 경우 반환 true 합니다.

다음 코드는 사용 및 Array.exists2.의 Array.exists 사용을 보여 줍니다. 이러한 예제에서는 이러한 경우 함수 인수 중 하나만 적용하여 새 함수를 만듭니다.

let allNegative = Array.exists (fun elem -> abs (elem) = elem) >> not
printfn "%A" (allNegative [| -1; -2; -3 |])
printfn "%A" (allNegative [| -10; -1; 5 |])
printfn "%A" (allNegative [| 0 |])


let haveEqualElement = Array.exists2 (fun elem1 elem2 -> elem1 = elem2)
printfn "%A" (haveEqualElement [| 1; 2; 3 |] [| 3; 2; 1|])

이전 코드의 출력은 다음과 같습니다.

true
false
false
true

마찬가지로 함수 Array.forall 는 배열을 테스트하여 모든 요소가 부울 조건을 충족하는지 여부를 확인합니다. 변형 Array.forall2 은 길이가 같은 두 배열의 요소를 포함하는 부울 함수를 사용하여 동일한 작업을 수행합니다. 다음 코드에서는 이러한 함수의 사용을 보여 줍니다.

let allPositive = Array.forall (fun elem -> elem > 0)
printfn "%A" (allPositive [| 0; 1; 2; 3 |])
printfn "%A" (allPositive [| 1; 2; 3 |])


let allEqual = Array.forall2 (fun elem1 elem2 -> elem1 = elem2)
printfn "%A" (allEqual [| 1; 2 |] [| 1; 2 |])
printfn "%A" (allEqual [| 1; 2 |] [| 2; 1 |])

이러한 예제의 출력은 다음과 같습니다.

false
true
true
false

배열 검색

Array.find 는 부울 함수를 사용하고 함수가 반환하는 첫 번째 요소를 반환 true하거나 조건을 충족하는 요소가 없으면 발생합니다 System.Collections.Generic.KeyNotFoundException . Array.findIndex 는 요소 자체 대신 요소의 인덱스가 반환된다는 점을 제외하고는 다음과 같습니다 Array.find.

다음 코드는 완벽한 정사각형 및 Array.findIndex 완벽한 큐브인 숫자를 사용하고 Array.find 찾습니다.

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

출력은 다음과 같습니다.

The first element that is both a square and a cube is 64 and its index is 62.

Array.tryFind는 결과가 옵션 형식이고 요소가 없으면 반환 None 된다는 점을 제외하고 다음과 같습니다Array.find. Array.tryFind 는 일치하는 요소가 배열에 있는지 여부를 모르는 경우 대신 Array.find 사용해야 합니다. 마찬가지로 Array.tryFindIndex 옵션 형식이 반환 값이라는 점을 제외하면 비슷합니다 Array.findIndex . 요소를 찾을 수 없는 경우 옵션은 .입니다 None.

다음 코드는 Array.tryFind의 사용법을 보여줍니다. 이 코드는 이전 코드에 따라 달라집니다.

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 lookForCubeAndSquare array1 =
    let result = Array.tryFind (fun elem -> isPerfectSquare elem && isPerfectCube elem) array1
    match result with
    | Some x -> printfn "Found an element: %d" x
    | None -> printfn "Failed to find a matching element."

lookForCubeAndSquare [| 1 .. 10 |]
lookForCubeAndSquare [| 100 .. 1000 |]
lookForCubeAndSquare [| 2 .. 50 |]

출력은 다음과 같습니다.

Found an element: 1
Found an element: 729
Failed to find a matching element.

요소를 찾는 것 외에도 변환해야 하는 경우에 사용합니다 Array.tryPick . 결과는 함수가 변환된 요소를 옵션 값으로 반환하거나 None 이러한 요소를 찾을 수 없는 경우 첫 번째 요소입니다.

다음 코드는 Array.tryPick의 사용법을 보여줍니다. 이 경우 람다 식 대신 코드를 간소화하기 위해 여러 로컬 도우미 함수가 정의됩니다.

let findPerfectSquareAndCube array1 =
    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
    // intFunction : (float -> float) -> int -> int
    // Allows the use of a floating point function with integers.
    let intFunction function1 number = int (round (function1 (float number)))
    let cubeRoot x = System.Math.Pow(x, 1.0/3.0)
    // testElement: int -> (int * int * int) option
    // Test an element to see whether it is a perfect square and a perfect
    // cube, and, if so, return the element, square root, and cube root
    // as an option value. Otherwise, return None.
    let testElement elem =
        if isPerfectSquare elem && isPerfectCube elem then
            Some(elem, intFunction sqrt elem, intFunction cubeRoot elem)
        else None
    match Array.tryPick testElement array1 with
    | Some (n, sqrt, cuberoot) -> printfn "Found an element %d with square root %d and cube root %d." n sqrt cuberoot
    | None -> printfn "Did not find an element that is both a perfect square and a perfect cube."

findPerfectSquareAndCube [| 1 .. 10 |]
findPerfectSquareAndCube [| 2 .. 100 |]
findPerfectSquareAndCube [| 100 .. 1000 |]
findPerfectSquareAndCube [| 1000 .. 10000 |]
findPerfectSquareAndCube [| 2 .. 50 |]

출력은 다음과 같습니다.

Found an element 1 with square root 1 and cube root 1.
Found an element 64 with square root 8 and cube root 4.
Found an element 729 with square root 27 and cube root 9.
Found an element 4096 with square root 64 and cube root 16.
Did not find an element that is both a perfect square and a perfect cube.

배열에서 계산 수행

이 함수는 Array.average 배열에 있는 각 요소의 평균을 반환합니다. 부동 소수점 형식을 포함하지만 정수 형식은 포함하지 않는 정수로 정확한 나누기를 지원하는 요소 형식으로 제한됩니다. 함수는 Array.averageBy 각 요소에 대해 함수를 호출한 결과의 평균을 반환합니다. 정수 계열 형식 배열의 경우 함수를 사용하여 Array.averageBy 각 요소를 계산을 위해 부동 소수점 형식으로 변환하도록 할 수 있습니다.

요소 형식이 지원하는 경우 최대 또는 최소 요소를 사용 Array.max 하거나 Array.min 가져옵니다. 마찬가지로, Array.maxByArray.minBy 먼저 함수를 실행하여 비교를 지원하는 형식으로 변환할 수 있습니다.

Array.sum 는 배열의 요소를 추가하고 각 Array.sumBy 요소에 대해 함수를 호출하고 결과를 함께 추가합니다.

반환 값을 Array.iter저장하지 않고 배열의 각 요소에서 함수를 실행하려면 . 길이가 같은 두 배열이 포함된 함수의 경우 .를 사용합니다 Array.iter2. 또한 함수 결과의 배열을 유지해야 하는 경우 한 번에 두 배열에서 작동하는 함수를 사용 Array.map 하거나 Array.map2사용합니다.

변형 및 Array.iteriArray.iteri2 요소의 인덱스가 계산 Array.mapiArray.mapi2에 포함되도록 허용합니다.

배열의 Array.foldArray.foldBackArray.reduce모든 요소를 포함하는 함수, , Array.reduceBack, Array.scanArray.scanBack 실행 알고리즘입니다. 마찬가지로 두 배열에 대한 변형 Array.fold2Array.foldBack2 계산을 수행합니다.

계산을 수행하기 위한 이러한 함수는 List 모듈에서 동일한 이름의 함수에 해당합니다. 사용 예제는 목록을 참조 하세요.

배열 수정

Array.set 는 요소를 지정된 값으로 설정합니다. Array.fill 는 배열의 요소 범위를 지정된 값으로 설정합니다. 다음 코드는 .의 Array.fill예를 제공합니다.

let arrayFill1 = [| 1 .. 25 |]
Array.fill arrayFill1 2 20 0
printfn "%A" arrayFill1

출력은 다음과 같습니다.

[|1; 2; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 23; 24; 25|]

한 배열의 하위 섹션을 다른 배열에 복사하는 데 사용할 Array.blit 수 있습니다.

다른 형식으로 변환 및 다른 형식에서 변환

Array.ofList 는 목록에서 배열을 만듭니다. Array.ofSeq 는 시퀀스에서 배열을 만듭니다. Array.toList 배열 Array.toSeq 형식에서 이러한 다른 컬렉션 형식으로 변환합니다.

배열 정렬

제네릭 비교 함수를 사용하여 배열을 정렬하는 데 사용합니다 Array.sort . 키에 대한 제네릭 비교 함수를 사용하여 정렬할 값을 생성하는 함수(키라고 함)를 지정하는 데 사용합니다Array.sortBy. 사용자 지정 비교 함수를 제공하려는 경우 사용합니다 Array.sortWith . Array.sortArray.sortByArray.sortWith 정렬된 배열을 새 배열로 반환합니다. 변형 및 Array.sortInPlaceArray.sortInPlaceByArray.sortInPlaceWith 새 배열을 반환하는 대신 기존 배열을 수정합니다.

배열 및 튜플

튜플 쌍의 배열을 배열의 튜플로 변환하고 그 반대로 변환 Array.zipArray.unzip 합니다. Array.zip3 3 Array.unzip3 개 요소의 튜플 또는 세 배열의 튜플로 작업한다는 점을 제외하면 유사합니다.

배열에 대한 병렬 계산

이 모듈 Array.Parallel 에는 배열에서 병렬 계산을 수행하기 위한 함수가 포함되어 있습니다. 이 모듈은 버전 4 이전의 .NET Framework 버전을 대상으로 하는 애플리케이션에서 사용할 수 없습니다.

참고 항목