@@ -19,18 +19,16 @@ module AdaptiveExtensions =
1919
2020 member cts.TryCancel () =
2121 try
22- if not <| isNull cts then
23- cts.Cancel()
22+ if not <| isNull cts then cts.Cancel()
2423 with
2524 | :? ObjectDisposedException
2625 | :? NullReferenceException -> ()
2726
2827 member cts.TryDispose () =
2928 try
30- if not <| isNull cts then
31- cts.Dispose()
32- with _ ->
33- ()
29+ if not <| isNull cts then cts.Dispose()
30+ with
31+ | _ -> ()
3432
3533
3634 type TaskCompletionSource < 'a > with
@@ -39,13 +37,15 @@ module AdaptiveExtensions =
3937 member tcs.TrySetFromTask ( real : Task < 'a >) =
4038
4139 // note: using ContinueWith instead of task CE for better stack traces
42- real.ContinueWith( fun ( task : Task < _ >) ->
40+ real.ContinueWith ( fun ( task : Task < _ >) ->
4341 match task.Status with
4442 | TaskStatus.RanToCompletion -> tcs.TrySetResult task.Result |> ignore< bool>
4543 | TaskStatus.Canceled ->
4644 tcs.TrySetCanceled( TaskCanceledException( task) .CancellationToken)
4745 |> ignore< bool>
48- | TaskStatus.Faulted -> tcs.TrySetException( task.Exception.InnerExceptions) |> ignore< bool>
46+ | TaskStatus.Faulted ->
47+ tcs.TrySetException( task.Exception.InnerExceptions)
48+ |> ignore< bool>
4949
5050 | _ -> ())
5151 |> ignore< Task>
@@ -83,13 +83,16 @@ module AdaptiveExtensions =
8383
8484
8585module Utils =
86- let cheapEqual ( a : 'T ) ( b : 'T ) = ShallowEqualityComparer< 'T>. Instance.Equals( a, b)
86+ let cheapEqual ( a : 'T ) ( b : 'T ) = ShallowEqualityComparer< 'T>. Instance.Equals ( a, b)
8787
8888/// <summary>
8989/// Maps and calls dispose before mapping of new values. Useful for cleaning up callbacks like AddMarkingCallback for tracing purposes.
9090/// </summary>
9191type MapDisposableTupleVal < 'T1 , 'T2 , 'Disposable when 'Disposable :> IDisposable >
92- ( mapping: 'T1 -> ( 'T2 * 'Disposable), input: aval< 'T1>) =
92+ (
93+ mapping: 'T1 -> ( 'T2 * 'Disposable),
94+ input: aval< 'T1>
95+ ) =
9396 inherit AVal.AbstractVal< 'T2>()
9497
9598 let mutable cache : ValueOption < struct ( 'T1 * 'T2 * 'Disposable )> = ValueNone
@@ -98,8 +101,8 @@ type MapDisposableTupleVal<'T1, 'T2, 'Disposable when 'Disposable :> IDisposable
98101 let i = input.GetValue token
99102
100103 match cache with
101- | ValueSome( struct ( a, b, _)) when Utils.cheapEqual a i -> b
102- | ValueSome( struct (_, _, c)) ->
104+ | ValueSome ( struct ( a, b, _)) when Utils.cheapEqual a i -> b
105+ | ValueSome ( struct (_, _, c)) ->
103106 ( c :> IDisposable) .Dispose()
104107 let ( b , c ) = mapping i
105108 cache <- ValueSome( struct ( i, b, c))
@@ -135,12 +138,13 @@ module AVal =
135138
136139 for op in HashSet.computeDelta lastDeps newDeps do
137140 match op with
138- | Add(_, d) ->
141+ | Add (_, d) ->
139142 // the new dependency needs to be evaluated with our token, s.t. we depend on it in the future
140143 d.GetValueUntyped token |> ignore
141- | Rem(_, d) ->
144+ | Rem (_, d) ->
142145 // we no longer need to depend on the old dependency so we can remove ourselves from its outputs
143- lock d.Outputs ( fun () -> d.Outputs.Remove x) |> ignore
146+ lock d.Outputs ( fun () -> d.Outputs.Remove x)
147+ |> ignore
144148
145149 lastDeps <- newDeps
146150
@@ -168,7 +172,10 @@ module AVal =
168172module ASet =
169173 /// Creates an amap with the keys from the set and the values given by mapping and
170174 /// adaptively applies the given mapping function to all elements and returns a new amap containing the results.
171- let mapAtoAMap mapper src = src |> ASet.mapToAMap mapper |> AMap.mapA ( fun _ v -> v)
175+ let mapAtoAMap mapper src =
176+ src
177+ |> ASet.mapToAMap mapper
178+ |> AMap.mapA ( fun _ v -> v)
172179
173180module AMap =
174181 open FSharp.Data .Traceable
@@ -261,12 +268,11 @@ module AMap =
261268
262269 cache <-
263270 match HashMap.tryRemove i cache with
264- | Some( o, remainingCache) ->
271+ | Some ( o, remainingCache) ->
265272 let rem , rest = MultiSetMap.remove o i targets
266273 targets <- rest
267274
268- if rem then
269- o.Outputs.Remove x |> ignore
275+ if rem then o.Outputs.Remove x |> ignore
270276
271277 remainingCache
272278 | None -> cache
@@ -325,7 +331,8 @@ module AMap =
325331 ( mapper : 'Key -> 'InValue -> aval < 'OutValue >)
326332 ( map : #amap<'Key , #aval<'InValue>> )
327333 : amap < 'Key , aval < 'OutValue >> =
328- map |> AMap.map ( fun k v -> AVal.bind ( mapper k) v)
334+ map
335+ |> AMap.map ( fun k v -> AVal.bind ( mapper k) v)
329336
330337
331338 /// Adaptively applies the given mapping to all changes and reapplies mapping on dirty outputs
@@ -346,7 +353,9 @@ module AMap =
346353 =
347354 let mapping =
348355 mapping
349- >> HashMap.map ( fun _ v -> AVal.constant v |> AVal.mapWithAdditionalDependencies id)
356+ >> HashMap.map ( fun _ v ->
357+ AVal.constant v
358+ |> AVal.mapWithAdditionalDependencies id)
350359
351360 batchRecalcDirty mapping map
352361
@@ -404,7 +413,7 @@ and AdaptiveCancellableTask<'a>(cancel: unit -> unit, real: Task<'a>) =
404413 real
405414 else
406415 cachedTcs <- new TaskCompletionSource< 'a>()
407- cachedTcs.TrySetFromTask real
416+ cachedTcs.TrySetFromTask real |> ignore < bool >
408417 cachedTcs.Task
409418
410419 cached <-
@@ -426,7 +435,8 @@ and AdaptiveCancellableTask<'a>(cancel: unit -> unit, real: Task<'a>) =
426435 cancel ()
427436
428437 if not <| isNull cachedTcs then
429- cachedTcs.TrySetCanceled( cancellationToken) |> ignore< bool>)
438+ cachedTcs.TrySetCanceled( cancellationToken)
439+ |> ignore< bool>)
430440
431441 /// <summary>The output of the passed in task to the constructor.</summary>
432442 /// <returns></returns>
@@ -647,7 +657,7 @@ module AsyncAVal =
647657 member x.Compute t =
648658 if x.OutOfDate || Option.isNone cache then
649659 let ref =
650- RefCountingTaskCreator( fun ct ->
660+ RefCountingTaskCreator ( fun ct ->
651661 task {
652662 let v = input.GetValue t
653663
@@ -656,7 +666,7 @@ module AsyncAVal =
656666 let! i = v.Task
657667
658668 match dataCache with
659- | ValueSome( struct ( oa, ob)) when Utils.cheapEqual oa i -> return ob
669+ | ValueSome ( struct ( oa, ob)) when Utils.cheapEqual oa i -> return ob
660670 | _ ->
661671 let! b = mapping i ct
662672 dataCache <- ValueSome( struct ( i, b))
@@ -696,21 +706,21 @@ module AsyncAVal =
696706 member x.Compute t =
697707 if x.OutOfDate || Option.isNone cache then
698708 let ref =
699- RefCountingTaskCreator( fun ct ->
709+ RefCountingTaskCreator ( fun ct ->
700710 task {
701711 let ta = ca.GetValue t
702712 let tb = cb.GetValue t
703713
704714 use _s =
705- ct.Register( fun () ->
715+ ct.Register ( fun () ->
706716 ta.Cancel( ct)
707717 tb.Cancel( ct))
708718
709719 let! ia = ta.Task
710720 let! ib = tb.Task
711721
712722 match dataCache with
713- | ValueSome( struct ( va, vb, vc)) when Utils.cheapEqual va ia && Utils.cheapEqual vb ib -> return vc
723+ | ValueSome ( struct ( va, vb, vc)) when Utils.cheapEqual va ia && Utils.cheapEqual vb ib -> return vc
714724 | _ ->
715725 let! vc = mapping ia ib ct
716726 dataCache <- ValueSome( struct ( ia, ib, vc))
@@ -747,17 +757,18 @@ module AsyncAVal =
747757
748758 member x.Compute t =
749759 if x.OutOfDate then
750- if Interlocked.Exchange(& inputChanged, 0 ) = 1 || Option.isNone cache then
760+ if Interlocked.Exchange(& inputChanged, 0 ) = 1
761+ || Option.isNone cache then
751762 let outerTask =
752- RefCountingTaskCreator( fun ct ->
763+ RefCountingTaskCreator ( fun ct ->
753764 task {
754765 let v = value.GetValue t
755766 use _s = ct.Register( fun () -> v.Cancel( ct))
756767
757768 let! i = v.Task
758769
759770 match outerDataCache with
760- | Some( struct ( oa, ob)) when Utils.cheapEqual oa i -> return ob
771+ | Some ( struct ( oa, ob)) when Utils.cheapEqual oa i -> return ob
761772 | _ ->
762773 let inner = mapping i ct
763774 outerDataCache <- Some( i, inner)
@@ -770,7 +781,7 @@ module AsyncAVal =
770781 let outerTask = cache.Value
771782
772783 let ref =
773- RefCountingTaskCreator( fun ct ->
784+ RefCountingTaskCreator ( fun ct ->
774785 task {
775786
776787 let inner = outerTask.New()
@@ -783,7 +794,7 @@ module AsyncAVal =
783794 let innerTask = inner.GetValue t
784795
785796 use _ s2 =
786- ct.Register( fun () ->
797+ ct.Register ( fun () ->
787798 innerTask.Cancel( ct)
788799 lock inners ( fun () -> inners.Value <- HashSet.remove inner inners.Value)
789800 inner.Outputs.Remove x |> ignore)
@@ -796,10 +807,10 @@ module AsyncAVal =
796807
797808 ref.New()
798809 else
799- innerCache.Value.New()
810+ innerCache.Value.New() }
811+ :>
800812
801- }
802- :> asyncaval<_>
813+ asyncaval<_>
803814
804815
805816 /// Returns a new async adaptive value that adaptively applies the mapping function to the given
@@ -877,7 +888,8 @@ module AMapAsync =
877888 ( mapper : 'Key -> 'InValue -> CancellationToken -> asyncaval < 'OutValue >)
878889 ( map : #amap<'Key , #aval<'InValue>> )
879890 : amap < 'Key , asyncaval < 'OutValue >> =
880- map |> AMap.map ( fun k v -> v |> AsyncAVal.ofAVal |> AsyncAVal.bind ( mapper k))
891+ map
892+ |> AMap.map ( fun k v -> v |> AsyncAVal.ofAVal |> AsyncAVal.bind ( mapper k))
881893
882894 /// <summary>
883895 /// Adaptively maps over the given map.
@@ -886,7 +898,8 @@ module AMapAsync =
886898 ( mapper : 'Key -> 'InValue -> CancellationToken -> asyncaval < 'OutValue >)
887899 ( map : #amap<'Key , #asyncaval<'InValue>> )
888900 : amap < 'Key , asyncaval < 'OutValue >> =
889- map |> AMap.map ( fun k v -> v |> AsyncAVal.bind ( mapper k))
901+ map
902+ |> AMap.map ( fun k v -> v |> AsyncAVal.bind ( mapper k))
890903
891904 /// Adaptively looks up the given key in the map and binds the value to be easily worked with. Note that this operation should not be used extensively since its resulting aval will be re-evaluated upon every change of the map.
892905 let tryFindA ( key : 'Key ) ( map : amap < 'Key , #asyncaval < 'Value >>) =
0 commit comments