//情報
type Info<'a, 'b, 'c>
(
f : 'a -> bool, //フィルター関数
m : 'a -> 'b, //マッピング関数
parentGetDataFunc : ( List<'c> -> List<'a> ) option //親の関数
) =
//フィールド
let _filter = f
let _map = m
let mutable parentFunc = parentGetDataFunc
member private this.Filter with get() = _filter
member private this.Map with get() = _map
member private this.PrentFunc with get() = parentFunc
//親を考慮してデータを取得する
static member (=>)( data : List<'c>, x : Info<'a, 'b, 'c> ) : List<'b> =
let newData = x.PrentFunc.Value( data )
newData => x
//親を考慮しないでデータを取得する
static member (=>)( data : List<'a>, x : Info<'a, 'b, 'c> ) : List<'b> =
data
|> List.filter x.Filter
|> List.map x.Map
//人間が認識する情報
type InfoSet<'a, 'b, 'c>
(
name : string, //識別するための名前
f : 'a -> bool, //フィルター関数
m : 'a -> 'b, //マッピング関数
parentGetDataFunc : ( List<'c> -> List<'a> ) option //親の関数
) =
inherit Info<'a, 'b, 'c>( f, m, parentGetDataFunc)
//エラーチェック
do
if name.Length = 0 then
raise <| System.ArgumentException( "必ず名前を指定してください。" )
//フィールド
let _name = name
//プロパティ
member this.Name with get() = _name
[<EntryPoint>]
let main argv =
//テストデータを準備
let source =
[
yield "実験データ"
for i in 0..10 -> i.ToString()
for i in -10..-1 -> i.ToString()
yield "終了"
]
printfn "元のデータ"
List.iter <| printf "%A " <| source
printfn "\n"
//人間が認識する情報(情報集合)には必ず名前が必要
let humanSet =
new InfoSet<string, string, obj>(
"情報集合", ( fun x -> true ), ( fun x -> x ), None )
let data = source => humanSet
printfn "%s" humanSet.Name
List.iter <| printf "%A " <| data
printfn "\n"
//終了
0