This project is read-only.
Chain of responsibility pattern

Category:
Design patterns
Description: Chain of responsibility pattern implementation shows how a request can go through different function (responsibility) by using pipeline. For more information, please go to http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern
Code:
let ChainOfResponsibility2() = 
let chainTemplate processFunction canContinue s =
if canContinue s then processFunction s
else s

let canContinueF _ = true
let processF x = x + 1

let chainFunction = chainTemplate processF canContinueF //combine two functions to get a chainFunction
let s = 1 |> chainFunction |> chainFunction
printfn "%A" s

Execution Result:
3

Last edited Sep 14, 2011 at 4:19 AM by ttliu2000, version 1

Comments

MusaJ May 7, 2015 at 8:50 PM 
why not simplify the example to, 3 lines or 2 only? as:

let processF x = x + 1
let s= 1 |> processF |> processF
s