Skip to content

Commit

Permalink
moved monadic operators, added monadic getQueryString
Browse files Browse the repository at this point in the history
  • Loading branch information
mausch committed Aug 30, 2011
1 parent 336522e commit 79eacbd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
6 changes: 6 additions & 0 deletions Figment/Extensions.fs
Expand Up @@ -12,6 +12,12 @@ open System.Text.RegularExpressions
open System.Web.Caching
open System.Linq

module Option =
let fromNull =
function
| null -> None
| a -> Some a

[<AutoOpen>]
module Extensions =
let internal bindingFlags = BindingFlags.NonPublic ||| BindingFlags.Instance
Expand Down
7 changes: 0 additions & 7 deletions Figment/Reader.fs
Expand Up @@ -4,10 +4,3 @@ type ReaderBuilder() =
member x.Bind(m, f) = fun c -> f (m c) c
member x.Return a = fun _ -> a
member x.ReturnFrom a = a
member x.map f m = x.Bind(m, fun a -> x.Return (f a))

[<AutoOpen>]
module ReaderOperators =
let internal r = ReaderBuilder()
let (>>.) m f = r.Bind(m, fun _ -> f)
let (>>=) m f = r.Bind(m,f)
9 changes: 8 additions & 1 deletion Figment/Result.fs
Expand Up @@ -12,6 +12,12 @@ module Result =

let result = ReaderBuilder()

let inline bind f m = result.Bind(m,f)
let inline combine a b = result.Bind(a, fun _ -> b)
let (>>=) = bind
let (>>.) = combine
let inline map f m = result.Bind(m, fun a -> result.Return (f a))

let empty : FAction = EmptyResult() |> fromActionResult

let view viewName model =
Expand Down Expand Up @@ -88,7 +94,8 @@ module Result =
do! contentType "application/javascript"
}

open Figment.ReaderOperators
let getQueryString (key: string) (ctx: ControllerContext) : string option =
ctx.Request.QueryString.[key] |> Option.fromNull

let xml data =
// charset?
Expand Down

0 comments on commit 79eacbd

Please sign in to comment.