takes a string and a Context It modifies the Response content with the string passed and sets the status code to Ok It returns the modified context as optional type let RADIUS radius shape = let circle = { Color = Red Radius = radius } {shape with Circle = circle} Records are immutable string -> Context -> Context option
takes a string and a Context It modifies the Response content with the string passed and sets the status code to NotFound It returns the modified context as optional type
takes a string and a Context It modifies the Response content with the string passed and sets the status code to BadRequest It returns the modified context as optional type
modifies the response let responseHandler statusCode content ctx = let res = {StatusCode = statusCode; Content = content} Some {ctx with Response = res} let OK = responseHandler Ok
the context’s Request It returns the context if it is Get else returns None Pattern Matching against booleans Context -> Context option let SQUARE shape = let rect = shape.Rectangle match rect.Height = rect.Width with | true -> Some shape | _ -> None
handlers looks for a particular HttpMethod let httpMethodFilter httpMethod ctx = match ctx.Request.HttpMethod = httpMethod with | true -> Some ctx | _ -> None let GET = httpMethodFilter Get
addition to a context. It verifies the string with the Path of the context’s Request It returns the context if it matches else returns None string -> Context -> Context option
Handler -> Context -> Context option // Handler -> Handler -> Handler let compose f1 f2 ctx = match f1 ctx with | Some ctx -> f2 ctx | None -> None Step 18 Function to compose functions
-> Context -> Context option // Choose :: Handler list -> Handler let rec fib n = match n with | 1 -> 1 | 2 -> 1 | n -> fib(n-1) + fib(n-2) let rec firstEven nums = match nums with | [] -> None | x :: xs -> match x % 2 = 0 with | true -> Some x | _ -> firstEven xs