F # 워크 플로 빌더를 계속 탐색하면서 빌더에서 예외 처리, 특히 "for..in..do "구조.F # 워크 플로 빌더 구현 : for..in..do 구문의 예외 처리
이 실험의 최종 목표는 예외가 발생할 경우에도 시퀀스 처리를 계속할 워크 플로 작성기입니다.
다음은 빌더의 메서드에 대한 예외가
(첫 번째 Directory.EnumerateFiles (DIR) 호출에서) 발생 지점이 끝날 때까지 전화를받을 표시되지 않기 때문에 아래에, 예를 들어, 작동하지 않습니다type failSafeSeq() =
member this.For(seq1, mapFunction) =
try
seq1 |> Seq.collect mapFunction
with
ex -> Console.WriteLine ex
Seq.empty
member this.Yield(yieldExpr) = yieldExpr |> Seq.singleton
member this.YieldFrom(yieldBang) = yieldBang
member this.Combine(a, b) = Seq.append a b
member this.Delay(delayFun) = delayFun()
member this.Zero() = Seq.empty
let failSafe = new failSafeSeq();
let rec allFilesSeq dir =
failSafe { for file in Directory.EnumerateFiles(dir) do yield file
for subdir in Directory.EnumerateDirectories dir do yield! (allFilesSeq subdir) }
[<EntryPoint>]
let main args =
allFilesSeq "C:\\System Volume Information\\" //almost guaranteed to cause an UnauthorizedAccessException on Windows systems at the first Directory.EnumerateFiles(dir) call.
|> Seq.iter Console.WriteLine
0
F # 워크 플로를 사용하면 가능합니까?
이 시점에서 나는 언어로서 F #을 탐색하려고하고 있으며 익숙하지 않은 개념에 익숙해졌습니다. 이 경우 F # 워크 플로의 경계와 기능을 탐색하려고합니다. 덧붙여서,이 예제를 읽은 후 "Maybe"모나드/워크 플로우의 반 대칭으로 시도하기로 결정했습니다. http://leibnizdream.wordpress.com/2008/10/21/why-use-computation-workflows-aka-monads -in-f /. 나중에 더 실용적인 코딩으로 이동하겠습니다 :). 답변 해주셔서 감사합니다! – Nathan
동일한 유형을 갖고 싶습니다. 결함 허용 파이프 라인. 솔루션에 대한 모든 진도? –