List.sortWith<'T> 함수(F#)

업데이트: 2010년 8월

지정된 비교 함수를 사용하여 지정된 목록을 정렬합니다.

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

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

// Signature:
List.sortWith : ('T -> 'T -> int) -> 'T list -> 'T list

// Usage:
List.sortWith comparer list

매개 변수

  • comparer
    형식: 'T -> 'T -> int

    목록 요소를 비교하는 함수입니다.

  • list
    형식: 'T list

    입력 목록입니다.

반환 값

정렬된 목록입니다.

설명

이는 안정된 정렬입니다. 즉, 동일한 요소의 원래 순서가 유지됩니다.

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

예제

다음 코드에서는 List.sortWith을 사용하는 방법을 보여 줍니다.

open System

let list1 = [ "<>"; "&"; "&&"; "&&&"; "<"; ">"; "|"; "||"; "|||" ]
printfn "Before sorting: "
list1 |> printfn "%A"
let sortFunction (string1:string) (string2:string) =
    if (string1.Length > string2.Length) then
       1
    else if (string1.Length < string2.Length) then
       -1
    else
        String.Compare(string1, string2)
List.sortWith sortFunction list1
|> printfn "After sorting:\n%A"

Output

  

플랫폼

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.List 모듈(F#)

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

변경 기록

날짜

변경 내용

이유

2010년 8월

코드 예제를 추가했습니다.

향상된 기능 관련 정보