Skip to content

Commit

Permalink
Merge pull request fsprojects#9 from panesofglass/master
Browse files Browse the repository at this point in the history
Additional cleanup
  • Loading branch information
forki committed Aug 5, 2013
2 parents af858d5 + 8f08354 commit 23e9e66
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 60 deletions.
34 changes: 5 additions & 29 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ let homepage = "https://github.com/panesofglass/FSharp.Reactive"
(* Directories *)
let buildDir = "./build/"
let packagesDir = "./packages/"
let docsDir = "./docs/"
let deployDir = "./deploy/"
let testDir = "./test/"

let nugetDir = "./nuget/"
let nugetLibDir = nugetDir @@ "lib/net40"
let nugetDocsDir = nugetDir @@ "docs"

(* Tools *)
let nugetPath = ".Nuget/nuget.exe"
Expand All @@ -48,7 +46,7 @@ let filesToZip =

(* Targets *)
Target "Clean" (fun _ ->
CleanDirs [buildDir; testDir; deployDir; docsDir; nugetDir; nugetLibDir; nugetDocsDir]
CleanDirs [buildDir; testDir; deployDir; nugetDir; nugetLibDir]
)

Target "BuildApp" (fun _ ->
Expand Down Expand Up @@ -79,45 +77,24 @@ Target "Test" (fun _ ->
OutputFile = testDir + "TestResults.xml" })
)

Target "GenerateDocumentation" (fun _ ->
!+ (buildDir + "FSharp.Reactive.dll")
|> Scan
|> Docu (fun p ->
{p with
ToolPath = "./lib/FAKE/tools/docu.exe"
TemplatesPath = "./lib/templates"
OutputPath = docsDir })
)

Target "CopyLicense" (fun _ ->
[ "LICENSE.txt" ] |> CopyTo buildDir
)

Target "ZipDocumentation" (fun _ ->
!+ (docsDir + "/**/*.*")
|> Scan
|> Zip docsDir (deployDir + sprintf "Documentation-%s.zip" version)
)

Target "BuildNuGet" (fun _ ->
XCopy (docsDir |> FullName) nugetDocsDir
[ buildDir + "FSharp.Reactive.dll"
buildDir + "FSharp.Reactive.pdb"
buildDir + "System.Reactive.Core.dll"
buildDir + "System.Reactive.Interfaces.dll"
buildDir + "System.Reactive.Linq.dll" ]
buildDir + "FSharp.Reactive.pdb" ]
|> CopyTo nugetLibDir

let rxVersion = GetPackageVersion packagesDir "Rx-Main"

let rxVersion = GetPackageVersion packagesDir "Rx-Linq"
NuGet (fun p ->
{p with
Authors = authors
Project = projectName
Description = projectDescription
Version = version
OutputPath = nugetDir
Dependencies = ["Rx-Linq", RequireExactly rxVersion]
Dependencies = ["Rx-Linq", rxVersion]
AccessKey = getBuildParamOrDefault "nugetkey" ""
ToolPath = nugetPath
Publish = hasBuildParam "nugetkey" })
Expand All @@ -142,8 +119,7 @@ Target "Default" DoNothing
(* Build Order *)
"Clean"
==> "BuildApp" <=> "BuildTest" <=> "CopyLicense"
==> "Test" <=> "GenerateDocumentation"
==> "ZipDocumentation"
==> "Test"
==> "BuildNuGet"
==> "DeployZip"
==> "Deploy"
Expand Down
61 changes: 30 additions & 31 deletions src/Observable.fs
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,24 @@ module Core =

type Observable with
/// Creates an observable sequence from the specified Subscribe method implementation.
static member Create (subscribe:'a IObserver -> unit -> unit) =
static member Create (subscribe: IObserver<'T> -> unit -> unit) =
Observable.Create(Func<_,_>(fun o -> Action(subscribe o)))

/// Creates an observable sequence from the specified Subscribe method implementation.
static member Create subscribe =
Observable.Create(Func<_,IDisposable> subscribe)

type IObservable<'a> with
type IObservable<'T> with
/// Subscribes to the Observable with just a next-function.
member this.Subscribe(onNext:'a -> unit) =
member this.Subscribe(onNext: 'T -> unit) =
this.Subscribe(Action<_> onNext)

/// Subscribes to the Observable with a next and an error-function.
member this.Subscribe(onNext:'a -> unit, onError:exn -> unit) =
member this.Subscribe(onNext: 'T -> unit, onError: exn -> unit) =
this.Subscribe(Action<_> onNext, Action<exn> onError)

/// Subscribes to the Observable with a next and a completion callback.
member this.Subscribe(onNext:'a -> unit, onCompleted:unit -> unit) =
member this.Subscribe(onNext: 'T -> unit, onCompleted: unit -> unit) =
this.Subscribe(Action<_> onNext, Action onCompleted)

/// Subscribes to the Observable with all 3 callbacks.
Expand All @@ -55,32 +55,32 @@ module Core =
type ObservableBuilder() =
member this.Return(x) =
Observable.Return x
member this.ReturnFrom(m:IObservable<_>) = m
member this.Bind(m: IObservable<'a>, f: 'a -> IObservable<'b>) =
member this.ReturnFrom(m: IObservable<_>) = m
member this.Bind(m: IObservable<'T>, f: 'T -> IObservable<'TNext>) =
m.SelectMany(Func<_,_> f)
member this.Combine(comp1:IObservable<'a>, comp2:IObservable<'a>) =
member this.Combine(comp1: IObservable<'T>, comp2: IObservable<'T>) =
Observable.Concat(comp1, comp2)
member this.Delay(f) =
Observable.Defer(f: Func<IObservable<'a>>)
Observable.Defer(f: Func<IObservable<'T>>)
member this.Zero() =
Observable.Empty()
member this.TryWith(m:IObservable<_>, h:exn -> IObservable<_>) =
member this.TryWith(m: IObservable<_>, h: exn -> IObservable<_>) =
Observable.Catch(m, h)
member this.TryFinally(m:IObservable<_>, compensation: unit -> unit) =
member this.TryFinally(m: IObservable<_>, compensation: unit -> unit) =
Observable.Finally(m, Action(compensation))
member this.Using(res:#IDisposable, body) =
member this.Using(res: #IDisposable, body) =
this.TryFinally(body res, fun () -> match res with null -> () | disp -> disp.Dispose())
member this.While(guard, m: IObservable<_>) =
if not (guard()) then
this.Zero()
Observable.Empty()
else
m.SelectMany(Func<_,_>(fun () -> this.While(guard, m)))
member this.For(sequence, body) =
Observable.For(sequence, body)
// TODO: Are these the correct implementation? Are they necessary?
member this.Yield(x) =
Observable.Return x
member this.YieldFrom(m:IObservable<_>) = m
member this.YieldFrom(m: IObservable<_>) = m

let observe = ObservableBuilder()

Expand All @@ -89,35 +89,35 @@ module Core =
module Observable =

/// Binds an observable to generate a subsequent observable.
let bind (f:'a -> IObservable<'b>) (m:IObservable<'a>) = m.SelectMany(Func<_,_> f)
let bind (f: 'T -> IObservable<'TNext>) (m: IObservable<'T>) = m.SelectMany(Func<_,_> f)

/// Creates an observable sequence from the specified Subscribe method implementation.
let create (f:'a IObserver -> (unit -> unit)) = Observable.Create f
let create (f: IObserver<'T> -> (unit -> unit)) = Observable.Create f

/// Generates an observable from an IEvent<_> as an EventPattern.
let fromEventPattern<'a> (target:obj) eventName =
let fromEventPattern<'T> (target:obj) eventName =
Observable.FromEventPattern(target, eventName)

/// Generates an empty observable
let empty<'a> = Observable.Empty<'a>()
let empty<'T> = Observable.Empty<'T>()

/// Takes the head of the elements
let head obs = Observable.FirstAsync(obs)

/// Merges the two observables
let merge (second:'a IObservable) (first:'a IObservable) = Observable.Merge(first, second)
let merge (second: IObservable<'T>) (first: IObservable<'T>) = Observable.Merge(first, second)

/// Creates a range as an observable
let range start count = Observable.Range(start, count)

/// Converts a seq into an observable
let toObservable (source:'a seq) = Observable.ToObservable(source)
let toObservable (source: seq<'T>) = Observable.ToObservable(source)

/// Converts an observable into a seq
let toEnumerable (source:'a IObservable) = Observable.ToEnumerable(source)
let toEnumerable (source: IObservable<'T>) = Observable.ToEnumerable(source)

/// Subscribes to the observable with all three callbacks
let subscribe onNext onError onCompleted (observable: 'a IObservable) =
let subscribe onNext onError onCompleted (observable: IObservable<'T>) =
observable.Subscribe(Observer.Create(Action<_> onNext, Action<_> onError, Action onCompleted))

/// Returns the observable sequence that reacts first
Expand All @@ -127,7 +127,7 @@ module Observable =
let both second first = Observable.And(first, second)

/// Merges two observable sequences into one observable sequence
let zip (second:'a IObservable) (first:'a IObservable) =
let zip (second: IObservable<'T>) (first: IObservable<'T>) =
let inner a b = a, b
Observable.Zip(first, second, Func<_,_,_> inner)

Expand All @@ -139,13 +139,13 @@ module Observable =
Observable.CombineLatest(first, second, Func<_,_,_> inner)

/// Concats (flattens) an observable of observables into an observable
/// ===> Observable.SelectMany(observable, Func<_,_>(fun (x:IObservable<'a>) -> x))
let concat (second:'a IObservable) (first:'a IObservable) = Observable.Concat(first, second)
/// ===> Observable.SelectMany(observable, Func<_,_>(fun (x:IObservable<'T>) -> x))
let concat (second: IObservable<'T>) (first: IObservable<'T>) = Observable.Concat(first, second)

/// maps the given observable with the given function
/// Maps the given observable with the given function
let map f source = Observable.Select(source, Func<_,_>(f))

/// maps the given observable with the given function
/// Maps the given observable with the given function
let mapi f source =
let inner x i = f i x
Observable.Select(source, Func<_,_,_> inner)
Expand Down Expand Up @@ -180,16 +180,16 @@ module Observable =
let exists f source = source |> skipWhile (not << f) |> (not << isEmpty)

/// Throttles the observable for the given interval
let throttle (interval:TimeSpan) source =
let throttle (interval: TimeSpan) source =
Observable.Throttle(source, interval)

/// Samples the observable at the given interval
let sample (interval:TimeSpan) source =
let sample (interval: TimeSpan) source =
Observable.Sample(source, interval)

/// Continues an observable sequence that is terminated
/// by an exception with the next observable sequence.
let catch (second:'a IObservable) first =
let catch (second: IObservable<'T>) first =
Observable.Catch(first, second)

/// Takes elements while the predicate is satisfied
Expand All @@ -208,4 +208,3 @@ module Observable =

/// Reduces the observable
let reduce f source = Observable.Aggregate(source, Func<_,_,_> f)

0 comments on commit 23e9e66

Please sign in to comment.