次の方法で共有


Array.scanBack<'T,'State> 関数 (F#)

Array.foldBack と同様ですが、中間結果と最終結果の両方を返します。

名前空間/モジュール パス: Microsoft.FSharp.Collections.Array

アセンブリ: FSharp.Core (FSharp.Core.dll 内)

// Signature:
Array.scanBack : ('T -> 'State -> 'State) -> 'T [] -> 'State -> 'State []

// Usage:
Array.scanBack folder array state

パラメーター

  • folder
    型: 'T -> 'State -> 'State

    入力要素を受け取って状態を更新する関数。

  • array
    型: 'T []

    入力配列。

  • state
    型: 'State

    初期状態です。

戻り値

状態値の配列。

解説

この関数は、コンパイルされたアセンブリでは ScanBack という名前です。 F# 以外の言語から、またはリフレクションを使用してこの関数にアクセスする場合は、この名前を使用します。

使用例

次のコードは、Array.scanArray.scanBack の動作の比較を示しています。

// An array of functions that transform  
// integers. (int -> int) 
let ops1 =
 [| fun x -> x + 1
    fun x -> x + 2
    fun x -> x - 5 |]

let ops2 =
 [| fun x -> x + 1
    fun x -> x * 5
    fun x -> x * x |]

// Compare scan and scanBack, which apply the 
// operations in the opposite order. 
let compareOpOrder ops x0 =
    let xs1 = Array.scan (fun x op -> op x) x0 ops
    let xs2 = Array.scanBack (fun op x -> op x) ops x0

    // Print the intermediate results 
    let xs = Array.zip xs1 (Array.rev xs2)
    for (x1, x2) in xs do
        printfn "%10d %10d" x1 x2
    printfn ""

compareOpOrder ops1 10
compareOpOrder ops2 10

出力

  

プラットフォーム

Windows 8、Windows 7、Windows Server 2012 で Windows Server 2008 R2

バージョン情報

F# コア ライブラリのバージョン

サポート: ポータブル 2.0、4.0

参照

関連項目

Collections.Array モジュール (F#)

Microsoft.FSharp.Collections 名前空間 (F#)