diff --git a/src/fsharp/FSharp.Core/array.fs b/src/fsharp/FSharp.Core/array.fs index 8d7ce38869d..b764e6db350 100644 --- a/src/fsharp/FSharp.Core/array.fs +++ b/src/fsharp/FSharp.Core/array.fs @@ -464,6 +464,18 @@ namespace Microsoft.FSharp.Collections | None -> loop(i+1) | Some res -> res loop 0 + + [] + let pickV chooser (array: _[]) = + checkNonNull "array" array + let rec loop i = + if i >= array.Length then + indexNotFound() + else + match chooser array.[i] with + | ValueNone -> loop(i+1) + | ValueSome res -> res + loop 0 [] let tryPick chooser (array: _[]) = @@ -474,6 +486,16 @@ namespace Microsoft.FSharp.Collections | None -> loop(i+1) | res -> res loop 0 + + [] + let tryPickV chooser (array: _[]) = + checkNonNull "array" array + let rec loop i = + if i >= array.Length then ValueNone else + match chooser array.[i] with + | ValueNone -> loop(i+1) + | res -> res + loop 0 [] let choose (chooser: 'T -> 'U Option) (array: 'T[]) = @@ -521,6 +543,53 @@ namespace Microsoft.FSharp.Collections Microsoft.FSharp.Primitives.Basics.Array.subUnchecked 0 count chunk1 else empty + + [] + let chooseV (chooser: 'T -> 'U ValueOption) (array: 'T[]) = + checkNonNull "array" array + + let mutable i = 0 + let mutable first = Unchecked.defaultof<'U> + let mutable found = false + while i < array.Length && not found do + let element = array.[i] + match chooser element with + | ValueNone -> i <- i + 1 + | ValueSome b -> first <- b; found <- true + + if i <> array.Length then + + let chunk1: 'U[] = Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked ((array.Length >>> 2) + 1) + chunk1.[0] <- first + let mutable count = 1 + i <- i + 1 + while count < chunk1.Length && i < array.Length do + let element = array.[i] + match chooser element with + | ValueNone -> () + | ValueSome b -> chunk1.[count] <- b + count <- count + 1 + i <- i + 1 + + if i < array.Length then + let chunk2: 'U[] = Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked (array.Length-i) + count <- 0 + while i < array.Length do + let element = array.[i] + match chooser element with + | ValueNone -> () + | ValueSome b -> chunk2.[count] <- b + count <- count + 1 + i <- i + 1 + + let res: 'U[] = Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked (chunk1.Length + count) + Array.Copy(chunk1, res, chunk1.Length) + Array.Copy(chunk2, 0, res, chunk1.Length, count) + res + else + Microsoft.FSharp.Primitives.Basics.Array.subUnchecked 0 count chunk1 + else + empty // The filter module is a space and performance for Array.filter based optimization that uses // a bitarray to store the results of the filtering of every element of the array. This means @@ -864,6 +933,18 @@ namespace Microsoft.FSharp.Collections loop s' loop state res.ToArray() + + [] + let unfoldV<'T, 'State> (generator: 'State -> ('T*'State) voption) (state: 'State) = + let res = ResizeArray<_>() + let rec loop state = + match generator state with + | ValueNone -> () + | ValueSome (x, s') -> + res.Add(x) + loop s' + loop state + res.ToArray() [] let unzip (array: _[]) = diff --git a/src/fsharp/FSharp.Core/array.fsi b/src/fsharp/FSharp.Core/array.fsi index 5ede87a3c6d..cf2f30900f2 100644 --- a/src/fsharp/FSharp.Core/array.fsi +++ b/src/fsharp/FSharp.Core/array.fsi @@ -150,6 +150,16 @@ namespace Microsoft.FSharp.Collections /// Thrown when the input array is null. [] val tryPick: chooser:('T -> 'U option) -> array:'T[] -> 'U option + + /// Applies the given function to successive elements, returning the first + /// result where function returns ValueSome(x) for some x. If the function + /// never returns ValueSome(x) then ValueNone is returned. + /// The function to transform the array elements into options. + /// The input array. + /// The first transformed element that is ValueSome(x). + /// Thrown when the input array is null. + [] + val tryPickV: chooser:('T -> 'U voption) -> array:'T[] -> 'U voption /// Fills a range of elements of the array with the given value. /// The target array. @@ -172,6 +182,18 @@ namespace Microsoft.FSharp.Collections /// The first result. [] val pick: chooser:('T -> 'U option) -> array:'T[] -> 'U + + /// Applies the given function to successive elements, returning the first + /// result where function returns ValueSome(x) for some x. If the function + /// never returns ValueSome(x) then KeyNotFoundException is raised. + /// The function to generate options from the elements. + /// The input array. + /// Thrown when the input array is null. + /// Thrown if every result from + /// chooser is ValueNone. + /// The first result. + [] + val pickV: chooser:('T -> 'U voption) -> array:'T[] -> 'U /// Applies the given function to each element of the array. Returns /// the array comprised of the results "x" for each element where @@ -182,6 +204,16 @@ namespace Microsoft.FSharp.Collections /// Thrown when the input array is null. [] val choose: chooser:('T -> 'U option) -> array:'T[] -> 'U[] + + /// Applies the given function to each element of the array. Returns + /// the array comprised of the results "x" for each element where + /// the function returns ValueSome(x) + /// The function to generate options from the elements. + /// The input array. + /// The array of results. + /// Thrown when the input array is null. + [] + val chooseV: chooser:('T -> 'U voption) -> array:'T[] -> 'U[] /// Divides the input array into chunks of size at most chunkSize. /// The maximum size of each chunk. @@ -1064,6 +1096,15 @@ namespace Microsoft.FSharp.Collections /// The result array. [] val unfold<'T,'State> : generator:('State -> ('T * 'State) option) -> state:'State -> 'T[] + + /// Returns an array that contains the elements generated by the given computation. + /// The given initial state argument is passed to the element generator. + /// A function that takes in the current state and returns an option tuple of the next + /// element of the array and the next state value. + /// The initial state value. + /// The result array. + [] + val unfoldV<'T,'State> : generator:('State -> ('T * 'State) voption) -> state:'State -> 'T[] /// Splits an array of pairs into two arrays. /// The input array. diff --git a/src/fsharp/FSharp.Core/eventmodule.fs b/src/fsharp/FSharp.Core/eventmodule.fs index 1d615a307c3..bd82e162bd8 100644 --- a/src/fsharp/FSharp.Core/eventmodule.fs +++ b/src/fsharp/FSharp.Core/eventmodule.fs @@ -37,6 +37,12 @@ namespace Microsoft.FSharp.Control let ev = new Event<_>() sourceEvent.Add(fun x -> match chooser x with None -> () | Some r -> ev.Trigger r) ev.Publish + + [] + let chooseV chooser (sourceEvent: IEvent<'Delegate,'T>) = + let ev = new Event<_>() + sourceEvent.Add(fun x -> match chooser x with ValueNone -> () | ValueSome r -> ev.Trigger r) + ev.Publish [] let scan collector state (sourceEvent: IEvent<'Delegate,'T>) = diff --git a/src/fsharp/FSharp.Core/eventmodule.fsi b/src/fsharp/FSharp.Core/eventmodule.fsi index c3f5f3cc9fb..f9bb22c38a9 100644 --- a/src/fsharp/FSharp.Core/eventmodule.fsi +++ b/src/fsharp/FSharp.Core/eventmodule.fsi @@ -58,6 +58,14 @@ namespace Microsoft.FSharp.Control /// An event that fires only when the chooser returns Some. [] val choose: chooser:('T -> 'U option) -> sourceEvent:IEvent<'Del,'T> -> IEvent<'U> + + /// Returns a new event which fires on a selection of messages from the original event. + /// The selection function takes an original message to an optional new message. + /// The function to select and transform event values to pass on. + /// The input event. + /// An event that fires only when the chooser returns ValueSome. + [] + val chooseV: chooser:('T -> 'U voption) -> sourceEvent:IEvent<'Del,'T> -> IEvent<'U> [] /// Returns a new event consisting of the results of applying the given accumulating function diff --git a/src/fsharp/FSharp.Core/list.fs b/src/fsharp/FSharp.Core/list.fs index 653c557a455..4fc2556286d 100644 --- a/src/fsharp/FSharp.Core/list.fs +++ b/src/fsharp/FSharp.Core/list.fs @@ -161,6 +161,9 @@ namespace Microsoft.FSharp.Collections [] let choose chooser list = Microsoft.FSharp.Primitives.Basics.List.choose chooser list + + [] + let chooseV chooser list = Microsoft.FSharp.Primitives.Basics.List.chooseV chooser list [] let splitAt index (list:'T list) = Microsoft.FSharp.Primitives.Basics.List.splitAt index list @@ -410,6 +413,15 @@ namespace Microsoft.FSharp.Collections match chooser h with | None -> tryPick chooser t | r -> r + + [] + let rec tryPickV chooser list = + match list with + | [] -> ValueNone + | h :: t -> + match chooser h with + | ValueNone -> tryPickV chooser t + | r -> r [] let rec pick chooser list = @@ -419,6 +431,15 @@ namespace Microsoft.FSharp.Collections match chooser h with | None -> pick chooser t | Some r -> r + + [] + let rec pickV chooser list = + match list with + | [] -> indexNotFound() + | h :: t -> + match chooser h with + | ValueNone -> pickV chooser t + | ValueSome r -> r [] let filter predicate list = Microsoft.FSharp.Primitives.Basics.List.filter predicate list @@ -700,3 +721,6 @@ namespace Microsoft.FSharp.Collections [] let unfold<'T, 'State> (generator:'State -> ('T*'State) option) (state:'State) = Microsoft.FSharp.Primitives.Basics.List.unfold generator state + + [] + let unfoldV<'T, 'State> (generator:'State -> ('T*'State) voption) (state:'State) = Microsoft.FSharp.Primitives.Basics.List.unfoldV generator state diff --git a/src/fsharp/FSharp.Core/list.fsi b/src/fsharp/FSharp.Core/list.fsi index aba9b3505b7..c3b7343ea39 100644 --- a/src/fsharp/FSharp.Core/list.fsi +++ b/src/fsharp/FSharp.Core/list.fsi @@ -60,6 +60,15 @@ namespace Microsoft.FSharp.Collections /// The list comprising the values selected from the chooser function. [] val choose: chooser:('T -> 'U option) -> list:'T list -> 'U list + + /// Applies the given function to each element of the list. Returns + /// the list comprised of the results x for each element where + /// the function returns ValueSome(x) + /// The function to generate options from the elements. + /// The input list. + /// The list comprising the values selected from the chooser function. + [] + val chooseV: chooser:('T -> 'U voption) -> list:'T list -> 'U list /// Divides the input list into chunks of size at most chunkSize. /// The maximum size of each chunk. @@ -575,6 +584,16 @@ namespace Microsoft.FSharp.Collections /// The first resulting value. [] val pick: chooser:('T -> 'U option) -> list:'T list -> 'U + + /// Applies the given function to successive elements, returning the first + /// result where function returns ValueSome(x) for some x. If no such + /// element exists then raise System.Collections.Generic.KeyNotFoundException + /// The function to generate options from the elements. + /// The input list. + /// Thrown when the list is empty. + /// The first resulting value. + [] + val pickV: chooser:('T -> 'U voption) -> list:'T list -> 'U /// Returns a list with all elements permuted according to the /// specified permutation. @@ -813,6 +832,15 @@ namespace Microsoft.FSharp.Collections /// The first resulting value or None. [] val tryPick: chooser:('T -> 'U option) -> list:'T list -> 'U option + + /// Applies the given function to successive elements, returning ValueSome(x) the first + /// result where function returns ValueSome(x) for some x. If no such element + /// exists then return ValueNone. + /// The function to generate options from the elements. + /// The input list. + /// The first resulting value or ValueNone. + [] + val tryPickV: chooser:('T -> 'U voption) -> list:'T list -> 'U voption /// Returns the first element for which the given function returns True. /// Return None if no such element exists. @@ -868,6 +896,15 @@ namespace Microsoft.FSharp.Collections /// The result list. [] val unfold<'T,'State> : generator:('State -> ('T * 'State) option) -> state:'State -> 'T list + + /// Returns a list that contains the elements generated by the given computation. + /// The given initial state argument is passed to the element generator. + /// A function that takes in the current state and returns an option tuple of the next + /// element of the list and the next state value. + /// The initial state value. + /// The result list. + [] + val unfoldV<'T,'State> : generator:('State -> ('T * 'State) voption) -> state:'State -> 'T list /// Splits a list of pairs into two lists. /// The input list. diff --git a/src/fsharp/FSharp.Core/local.fs b/src/fsharp/FSharp.Core/local.fs index 0f5c69160d0..6a6688b9aa6 100644 --- a/src/fsharp/FSharp.Core/local.fs +++ b/src/fsharp/FSharp.Core/local.fs @@ -184,6 +184,17 @@ module internal List = setFreshConsTail cons cons2 chooseToFreshConsTail cons2 f t + let rec chooseToFreshConsTailV cons f xs = + match xs with + | [] -> setFreshConsTail cons [] + | h :: t -> + match f h with + | ValueNone -> chooseToFreshConsTailV cons f t + | ValueSome x -> + let cons2 = freshConsNoTail x + setFreshConsTail cons cons2 + chooseToFreshConsTailV cons2 f t + let rec choose f xs = match xs with | [] -> [] @@ -195,6 +206,17 @@ module internal List = chooseToFreshConsTail cons f t cons + let rec chooseV f xs = + match xs with + | [] -> [] + | h :: t -> + match f h with + | ValueNone -> chooseV f t + | ValueSome x -> + let cons = freshConsNoTail x + chooseToFreshConsTailV cons f t + cons + let groupBy (comparer:IEqualityComparer<'SafeKey>) (keyf:'T->'SafeKey) (getKey:'SafeKey->'Key) (list: 'T list) = match list with | [] -> [] @@ -778,6 +800,14 @@ module internal List = setFreshConsTail cons cons2 unfoldToFreshConsTail cons2 f s' + let rec unfoldToFreshConsTailV cons f s = + match f s with + | ValueNone -> setFreshConsTail cons [] + | ValueSome (x, s') -> + let cons2 = freshConsNoTail x + setFreshConsTail cons cons2 + unfoldToFreshConsTailV cons2 f s' + let unfold (f:'State -> ('T * 'State) option) (s:'State) = match f s with | None -> [] @@ -786,6 +816,14 @@ module internal List = unfoldToFreshConsTail cons f s' cons + let unfoldV (f:'State -> ('T * 'State) voption) (s:'State) = + match f s with + | ValueNone -> [] + | ValueSome (x, s') -> + let cons = freshConsNoTail x + unfoldToFreshConsTailV cons f s' + cons + // optimized mutation-based implementation. This code is only valid in fslib, where mutation of private // tail cons cells is permitted in carefully written library code. let rec unzipToFreshConsTail cons1a cons1b x = diff --git a/src/fsharp/FSharp.Core/local.fsi b/src/fsharp/FSharp.Core/local.fsi index 3181dcbc6ec..7c48deaf7b3 100644 --- a/src/fsharp/FSharp.Core/local.fsi +++ b/src/fsharp/FSharp.Core/local.fsi @@ -26,6 +26,7 @@ open Microsoft.FSharp.Collections module internal List = val allPairs : 'T1 list -> 'T2 list -> ('T1 * 'T2) list val choose: ('T -> 'U option) -> 'T list -> 'U list + val chooseV: ('T -> 'U voption) -> 'T list -> 'U list val countBy : System.Collections.Generic.Dictionary<'T1, int> -> ('T1 -> 'T2) -> ('T2 * int) list val pairwise : 'T list -> ('T * 'T) list val groupBy : System.Collections.Generic.IEqualityComparer<'SafeKey> -> ('T->'SafeKey) -> ('SafeKey->'Key) -> 'T list -> ('Key*'T list) list @@ -50,6 +51,7 @@ module internal List = val concat : seq<'T list> -> 'T list val iteri : action:(int -> 'T -> unit) -> 'T list -> unit val unfold : ('State -> ('T * 'State) option) -> 'State -> 'T list + val unfoldV : ('State -> ('T * 'State) voption) -> 'State -> 'T list val unzip : ('T1 * 'T2) list -> 'T1 list * 'T2 list val unzip3 : ('T1 * 'T2 * 'T3) list -> 'T1 list * 'T2 list * 'T3 list val windowed : int -> 'T list -> 'T list list diff --git a/src/fsharp/FSharp.Core/map.fs b/src/fsharp/FSharp.Core/map.fs index d701fb87cfa..1435ce3cbad 100644 --- a/src/fsharp/FSharp.Core/map.fs +++ b/src/fsharp/FSharp.Core/map.fs @@ -248,9 +248,25 @@ module MapTree = | Some _ as res -> res | None -> tryPickOpt f r + + let rec tryPickOptV (f: OptimizedClosures.FSharpFunc<_, _, _>) m = + match m with + | MapEmpty -> ValueNone + | MapOne (k2, v2) -> f.Invoke (k2, v2) + | MapNode (k2, v2, l, r, _) -> + match tryPickOptV f l with + | ValueSome _ as res -> res + | ValueNone -> + match f.Invoke (k2, v2) with + | ValueSome _ as res -> res + | ValueNone -> + tryPickOptV f r let tryPick f m = tryPickOpt (OptimizedClosures.FSharpFunc<_, _, _>.Adapt f) m + + let tryPickV f m = + tryPickOptV (OptimizedClosures.FSharpFunc<_, _, _>.Adapt f) m let rec existsOpt (f: OptimizedClosures.FSharpFunc<_, _, _>) m = match m with @@ -530,6 +546,9 @@ type Map<[]'Key, [] let tryPick chooser (table: Map<_, _>) = table.TryPick chooser + + [] + let tryPickV chooser (table: Map<_, _>) = + table.TryPickV chooser [] let pick chooser (table: Map<_, _>) = match tryPick chooser table with | None -> raise (KeyNotFoundException()) | Some res -> res + + [] + let pickV chooser (table: Map<_, _>) = + match tryPickV chooser table with + | ValueNone -> raise (KeyNotFoundException()) + | ValueSome res -> res [] let exists predicate (table: Map<_, _>) = diff --git a/src/fsharp/FSharp.Core/map.fsi b/src/fsharp/FSharp.Core/map.fsi index 9a702596a4c..a51906c7395 100644 --- a/src/fsharp/FSharp.Core/map.fsi +++ b/src/fsharp/FSharp.Core/map.fsi @@ -151,6 +151,13 @@ namespace Microsoft.FSharp.Collections /// The first result. [] val tryPick: chooser:('Key -> 'T -> 'U option) -> table:Map<'Key,'T> -> 'U option + + /// Searches the map looking for the first element where the given function returns a ValueSome value. + /// The function to generate options from the key/value pairs. + /// The input map. + /// The first result. + [] + val tryPickV: chooser:('Key -> 'T -> 'U voption) -> table:Map<'Key,'T> -> 'U voption /// Searches the map looking for the first element where the given function returns a Some value /// The function to generate options from the key/value pairs. @@ -158,6 +165,13 @@ namespace Microsoft.FSharp.Collections /// The first result. [] val pick: chooser:('Key -> 'T -> 'U option) -> table:Map<'Key,'T> -> 'U + + /// Searches the map looking for the first element where the given function returns a ValueSome value + /// The function to generate options from the key/value pairs. + /// The input map. + /// The first result. + [] + val pickV: chooser:('Key -> 'T -> 'U voption) -> table:Map<'Key,'T> -> 'U /// Folds over the bindings in the map. /// The function to update the state given the input key/value pairs. diff --git a/src/fsharp/FSharp.Core/observable.fs b/src/fsharp/FSharp.Core/observable.fs index 75ef1d081b1..39d0db367fd 100644 --- a/src/fsharp/FSharp.Core/observable.fs +++ b/src/fsharp/FSharp.Core/observable.fs @@ -70,6 +70,20 @@ namespace Microsoft.FSharp.Control member x.Error(e) = observer.OnError(e) member x.Completed() = observer.OnCompleted() } } + + [] + let chooseV chooser (source: IObservable<'T>) = + { new IObservable<'U> with + member x.Subscribe(observer) = + source.Subscribe + { new BasicObserver<'T>() with + + member x.Next(v) = + protect (fun () -> chooser v) (function ValueNone -> () | ValueSome v2 -> observer.OnNext v2) observer.OnError + + member x.Error(e) = observer.OnError(e) + + member x.Completed() = observer.OnCompleted() } } [] let filter predicate (source: IObservable<'T>) = diff --git a/src/fsharp/FSharp.Core/observable.fsi b/src/fsharp/FSharp.Core/observable.fsi index 36cbee5700d..7db77add404 100644 --- a/src/fsharp/FSharp.Core/observable.fsi +++ b/src/fsharp/FSharp.Core/observable.fsi @@ -86,6 +86,17 @@ namespace Microsoft.FSharp.Control [] val choose: chooser:('T -> 'U option) -> source:IObservable<'T> -> IObservable<'U> + /// Returns an observable which chooses a projection of observations from the source + /// using the given function. The returned object will trigger observations x + /// for which the splitter returns ValueSome x. The returned object also propagates + /// all errors arising from the source and completes when the source completes. + /// The function that returns ValueSome for observations to be propagated + /// and ValueNone for observations to ignore. + /// The input Observable. + /// An Observable that only propagates some of the observations from the source. + [] + val chooseV: chooser:('T -> 'U voption) -> source:IObservable<'T> -> IObservable<'U> + /// Returns an observable which, for each observer, allocates an item of state /// and applies the given accumulating function to successive values arising from /// the input. The returned object will trigger observations for each computed diff --git a/src/fsharp/FSharp.Core/seq.fs b/src/fsharp/FSharp.Core/seq.fs index ab48146b631..2629a47c77c 100644 --- a/src/fsharp/FSharp.Core/seq.fs +++ b/src/fsharp/FSharp.Core/seq.fs @@ -181,6 +181,29 @@ namespace Microsoft.FSharp.Collections member __.Reset() = noReset() interface System.IDisposable with member __.Dispose() = e.Dispose() } + + let chooseV f (e : IEnumerator<'T>) = + let started = ref false + let curr = ref ValueNone + let get() = + check !started + match !curr with + | ValueNone -> alreadyFinished() + | ValueSome x -> x + + { new IEnumerator<'U> with + member __.Current = get() + interface IEnumerator with + member __.Current = box (get()) + member __.MoveNext() = + if not !started then started := true + curr := ValueNone + while ((!curr).IsNone && e.MoveNext()) do + curr := f e.Current + ValueOption.isSome !curr + member __.Reset() = noReset() + interface System.IDisposable with + member __.Dispose() = e.Dispose() } let filter f (e : IEnumerator<'T>) = let started = ref false @@ -212,6 +235,20 @@ namespace Microsoft.FSharp.Collections true member __.Dispose() = () } + + let unfoldV f x : IEnumerator<_> = + let state = ref x + upcast + { new MapEnumerator<_>() with + member __.DoMoveNext curr = + match f !state with + | ValueNone -> false + | ValueSome (r,s) -> + curr <- r + state := s + true + member __.Dispose() = () + } let upto lastOption f = match lastOption with @@ -468,6 +505,7 @@ namespace Microsoft.FSharp.Collections let mkDelayedSeq (f: unit -> IEnumerable<'T>) = mkSeq (fun () -> f().GetEnumerator()) let mkUnfoldSeq f x = mkSeq (fun () -> IEnumerator.unfold f x) + let mkUnfoldVSeq f x = mkSeq (fun () -> IEnumerator.unfoldV f x) let inline indexNotFound() = raise (new System.Collections.Generic.KeyNotFoundException(SR.GetString(SR.keyNotFoundAlt))) [] @@ -475,6 +513,9 @@ namespace Microsoft.FSharp.Collections [] let unfold generator state = mkUnfoldSeq generator state + + [] + let unfoldV generator state = mkUnfoldVSeq generator state [] let empty<'T> = (EmptyEnumerable :> seq<'T>) @@ -618,6 +659,11 @@ namespace Microsoft.FSharp.Collections let choose chooser source = checkNonNull "source" source revamp (IEnumerator.choose chooser) source + + [] + let chooseV chooser source = + checkNonNull "source" source + revamp (IEnumerator.chooseV chooser) source [] let indexed source = @@ -650,6 +696,15 @@ namespace Microsoft.FSharp.Collections while (Option.isNone res && e.MoveNext()) do res <- chooser e.Current res + + [] + let tryPickV chooser (source : seq<'T>) = + checkNonNull "source" source + use e = source.GetEnumerator() + let mutable res = ValueNone + while (ValueOption.isNone res && e.MoveNext()) do + res <- chooser e.Current + res [] let pick chooser source = @@ -657,6 +712,13 @@ namespace Microsoft.FSharp.Collections match tryPick chooser source with | None -> indexNotFound() | Some x -> x + + [] + let pickV chooser source = + checkNonNull "source" source + match tryPickV chooser source with + | ValueNone -> indexNotFound() + | ValueSome x -> x [] let tryFind predicate (source : seq<'T>) = diff --git a/src/fsharp/FSharp.Core/seq.fsi b/src/fsharp/FSharp.Core/seq.fsi index 9ed5bed0965..e170bf314c8 100644 --- a/src/fsharp/FSharp.Core/seq.fsi +++ b/src/fsharp/FSharp.Core/seq.fsi @@ -136,6 +136,23 @@ namespace Microsoft.FSharp.Collections /// Thrown when the input sequence is null. [] val choose: chooser:('T -> 'U option) -> source:seq<'T> -> seq<'U> + + /// Applies the given function to each element of the list. Return + /// the list comprised of the results "x" for each element where + /// the function returns ValueSome(x). + /// + /// The returned sequence may be passed between threads safely. However, + /// individual IEnumerator values generated from the returned sequence should not + /// be accessed concurrently. + /// + /// A function to transform items of type T into options of type U. + /// The input sequence of type T. + /// + /// The result sequence. + /// + /// Thrown when the input sequence is null. + [] + val chooseV: chooser:('T -> 'U voption) -> source:seq<'T> -> seq<'U> /// Divides the input sequence into chunks of size at most chunkSize. /// The maximum size of each chunk. @@ -928,6 +945,20 @@ namespace Microsoft.FSharp.Collections /// evaluates to None when the given function is applied. [] val pick: chooser:('T -> 'U option) -> source:seq<'T> -> 'U + + /// Applies the given function to successive elements, returning the first + /// x where the function returns "ValueSome(x)". + /// + /// A function to transform each item of the input sequence into an option of the output type. + /// The input sequence. + /// + /// The selected element. + /// + /// Thrown when the input sequence is null. + /// Thrown when every item of the sequence + /// evaluates to None when the given function is applied. + [] + val pickV: chooser:('T -> 'U voption) -> source:seq<'T> -> 'U /// Builds a new sequence object that delegates to the given sequence object. This ensures /// the original sequence cannot be rediscovered and mutated by a type cast. For example, @@ -1285,6 +1316,18 @@ namespace Microsoft.FSharp.Collections /// Thrown when the input sequence is null. [] val tryPick: chooser:('T -> 'U option) -> source:seq<'T> -> 'U option + + /// Applies the given function to successive elements, returning the first + /// result where the function returns "ValueSome(x)". + /// + /// A function that transforms items from the input sequence into options. + /// The input sequence. + /// + /// The chosen element or ValueNone. + /// + /// Thrown when the input sequence is null. + [] + val tryPickV: chooser:('T -> 'U voption) -> source:seq<'T> -> 'U voption /// Returns the transpose of the given sequence of sequences. /// This function returns a sequence that digests the whole initial sequence as soon as @@ -1325,6 +1368,25 @@ namespace Microsoft.FSharp.Collections /// The result sequence. [] val unfold : generator:('State -> ('T * 'State) option) -> state:'State -> seq<'T> + + /// Returns a sequence that contains the elements generated by the given computation. + /// The given initial state argument is passed to the element generator. + /// For each IEnumerator elements in the stream are generated on-demand by applying the element + /// generator, until a None value is returned by the element generator. Each call to the element + /// generator returns a new residual state. + /// + /// The stream will be recomputed each time an IEnumerator is requested and iterated for the Seq. + /// + /// The returned sequence may be passed between threads safely. However, + /// individual IEnumerator values generated from the returned sequence should not be accessed concurrently. + /// + /// A function that takes in the current state and returns an option tuple of the next + /// element of the sequence and the next state value. + /// The initial state value. + /// + /// The result sequence. + [] + val unfoldV : generator:('State -> ('T * 'State) voption) -> state:'State -> seq<'T> /// Returns a sequence that yields sliding windows containing elements drawn from the input /// sequence. Each window is returned as a fresh array. diff --git a/tests/FSharp.Core.UnitTests/SurfaceArea.coreclr.fs b/tests/FSharp.Core.UnitTests/SurfaceArea.coreclr.fs index 9de6db290bd..40803ff34cc 100644 --- a/tests/FSharp.Core.UnitTests/SurfaceArea.coreclr.fs +++ b/tests/FSharp.Core.UnitTests/SurfaceArea.coreclr.fs @@ -96,6 +96,7 @@ Microsoft.FSharp.Collections.ArrayModule: Microsoft.FSharp.Core.FSharpOption`1[T Microsoft.FSharp.Collections.ArrayModule: Microsoft.FSharp.Core.FSharpOption`1[T] TryHead[T](T[]) Microsoft.FSharp.Collections.ArrayModule: Microsoft.FSharp.Core.FSharpOption`1[T] TryItem[T](Int32, T[]) Microsoft.FSharp.Collections.ArrayModule: Microsoft.FSharp.Core.FSharpOption`1[T] TryLast[T](T[]) +Microsoft.FSharp.Collections.ArrayModule: Microsoft.FSharp.Core.FSharpValueOption`1[TResult] TryPickV[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpValueOption`1[TResult]], T[]) Microsoft.FSharp.Collections.ArrayModule: System.Collections.Generic.IEnumerable`1[T] ToSeq[T](T[]) Microsoft.FSharp.Collections.ArrayModule: System.String ToString() Microsoft.FSharp.Collections.ArrayModule: System.Tuple`2[System.Int32,T][] Indexed[T](T[]) @@ -129,8 +130,10 @@ Microsoft.FSharp.Collections.ArrayModule: T ReduceBack[T](Microsoft.FSharp.Core. Microsoft.FSharp.Collections.ArrayModule: T Reduce[T](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpFunc`2[T,T]], T[]) Microsoft.FSharp.Collections.ArrayModule: T Sum[T](T[]) Microsoft.FSharp.Collections.ArrayModule: TResult AverageBy[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult], T[]) +Microsoft.FSharp.Collections.ArrayModule: TResult PickV[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpValueOption`1[TResult]], T[]) Microsoft.FSharp.Collections.ArrayModule: TResult Pick[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpOption`1[TResult]], T[]) Microsoft.FSharp.Collections.ArrayModule: TResult SumBy[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult], T[]) +Microsoft.FSharp.Collections.ArrayModule: TResult[] ChooseV[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpValueOption`1[TResult]], T[]) Microsoft.FSharp.Collections.ArrayModule: TResult[] Choose[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpOption`1[TResult]], T[]) Microsoft.FSharp.Collections.ArrayModule: TResult[] Collect[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult[]], T[]) Microsoft.FSharp.Collections.ArrayModule: TResult[] Map2[T1,T2,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T1,Microsoft.FSharp.Core.FSharpFunc`2[T2,TResult]], T1[], T2[]) @@ -172,6 +175,7 @@ Microsoft.FSharp.Collections.ArrayModule: T[] Tail[T](T[]) Microsoft.FSharp.Collections.ArrayModule: T[] TakeWhile[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], T[]) Microsoft.FSharp.Collections.ArrayModule: T[] Take[T](Int32, T[]) Microsoft.FSharp.Collections.ArrayModule: T[] Truncate[T](Int32, T[]) +Microsoft.FSharp.Collections.ArrayModule: T[] UnfoldV[T,TState](Microsoft.FSharp.Core.FSharpFunc`2[TState,Microsoft.FSharp.Core.FSharpValueOption`1[System.Tuple`2[T,TState]]], TState) Microsoft.FSharp.Collections.ArrayModule: T[] Unfold[T,TState](Microsoft.FSharp.Core.FSharpFunc`2[TState,Microsoft.FSharp.Core.FSharpOption`1[System.Tuple`2[T,TState]]], TState) Microsoft.FSharp.Collections.ArrayModule: T[] Where[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], T[]) Microsoft.FSharp.Collections.ArrayModule: T[] ZeroCreate[T](Int32) @@ -306,6 +310,7 @@ Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[System.Tuple`2[TKey,Microsoft.FSharp.Collections.FSharpList`1[T]]] GroupBy[T,TKey](Microsoft.FSharp.Core.FSharpFunc`2[T,TKey], Microsoft.FSharp.Collections.FSharpList`1[T]) Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[System.Tuple`2[TKey,System.Int32]] CountBy[T,TKey](Microsoft.FSharp.Core.FSharpFunc`2[T,TKey], Microsoft.FSharp.Collections.FSharpList`1[T]) Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[System.Tuple`3[T1,T2,T3]] Zip3[T1,T2,T3](Microsoft.FSharp.Collections.FSharpList`1[T1], Microsoft.FSharp.Collections.FSharpList`1[T2], Microsoft.FSharp.Collections.FSharpList`1[T3]) +Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[TResult] ChooseV[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpValueOption`1[TResult]], Microsoft.FSharp.Collections.FSharpList`1[T]) Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[TResult] Choose[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpOption`1[TResult]], Microsoft.FSharp.Collections.FSharpList`1[T]) Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[TResult] Collect[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Collections.FSharpList`1[TResult]], Microsoft.FSharp.Collections.FSharpList`1[T]) Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[TResult] Map2[T1,T2,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T1,Microsoft.FSharp.Core.FSharpFunc`2[T2,TResult]], Microsoft.FSharp.Collections.FSharpList`1[T1], Microsoft.FSharp.Collections.FSharpList`1[T2]) @@ -340,6 +345,7 @@ Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] TakeWhile[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], Microsoft.FSharp.Collections.FSharpList`1[T]) Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Take[T](Int32, Microsoft.FSharp.Collections.FSharpList`1[T]) Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Truncate[T](Int32, Microsoft.FSharp.Collections.FSharpList`1[T]) +Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] UnfoldV[T,TState](Microsoft.FSharp.Core.FSharpFunc`2[TState,Microsoft.FSharp.Core.FSharpValueOption`1[System.Tuple`2[T,TState]]], TState) Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Unfold[T,TState](Microsoft.FSharp.Core.FSharpFunc`2[TState,Microsoft.FSharp.Core.FSharpOption`1[System.Tuple`2[T,TState]]], TState) Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Where[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], Microsoft.FSharp.Collections.FSharpList`1[T]) Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Core.FSharpOption`1[System.Int32] TryFindIndexBack[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], Microsoft.FSharp.Collections.FSharpList`1[T]) @@ -350,6 +356,7 @@ Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Core.FSharpOption`1[T] Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Core.FSharpOption`1[T] TryHead[T](Microsoft.FSharp.Collections.FSharpList`1[T]) Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Core.FSharpOption`1[T] TryItem[T](Int32, Microsoft.FSharp.Collections.FSharpList`1[T]) Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Core.FSharpOption`1[T] TryLast[T](Microsoft.FSharp.Collections.FSharpList`1[T]) +Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Core.FSharpValueOption`1[TResult] TryPickV[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpValueOption`1[TResult]], Microsoft.FSharp.Collections.FSharpList`1[T]) Microsoft.FSharp.Collections.ListModule: System.Collections.Generic.IEnumerable`1[T] ToSeq[T](Microsoft.FSharp.Collections.FSharpList`1[T]) Microsoft.FSharp.Collections.ListModule: System.String ToString() Microsoft.FSharp.Collections.ListModule: System.Tuple`2[Microsoft.FSharp.Collections.FSharpList`1[T1],Microsoft.FSharp.Collections.FSharpList`1[T2]] Unzip[T1,T2](Microsoft.FSharp.Collections.FSharpList`1[System.Tuple`2[T1,T2]]) @@ -376,6 +383,7 @@ Microsoft.FSharp.Collections.ListModule: T ReduceBack[T](Microsoft.FSharp.Core.F Microsoft.FSharp.Collections.ListModule: T Reduce[T](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpFunc`2[T,T]], Microsoft.FSharp.Collections.FSharpList`1[T]) Microsoft.FSharp.Collections.ListModule: T Sum[T](Microsoft.FSharp.Collections.FSharpList`1[T]) Microsoft.FSharp.Collections.ListModule: TResult AverageBy[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult], Microsoft.FSharp.Collections.FSharpList`1[T]) +Microsoft.FSharp.Collections.ListModule: TResult PickV[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpValueOption`1[TResult]], Microsoft.FSharp.Collections.FSharpList`1[T]) Microsoft.FSharp.Collections.ListModule: TResult Pick[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpOption`1[TResult]], Microsoft.FSharp.Collections.FSharpList`1[T]) Microsoft.FSharp.Collections.ListModule: TResult SumBy[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult], Microsoft.FSharp.Collections.FSharpList`1[T]) Microsoft.FSharp.Collections.ListModule: TState Fold2[T1,T2,TState](Microsoft.FSharp.Core.FSharpFunc`2[TState,Microsoft.FSharp.Core.FSharpFunc`2[T1,Microsoft.FSharp.Core.FSharpFunc`2[T2,TState]]], TState, Microsoft.FSharp.Collections.FSharpList`1[T1], Microsoft.FSharp.Collections.FSharpList`1[T2]) @@ -406,6 +414,7 @@ Microsoft.FSharp.Collections.MapModule: Microsoft.FSharp.Collections.FSharpMap`2 Microsoft.FSharp.Collections.MapModule: Microsoft.FSharp.Core.FSharpOption`1[TKey] TryFindKey[TKey,T](Microsoft.FSharp.Core.FSharpFunc`2[TKey,Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean]], Microsoft.FSharp.Collections.FSharpMap`2[TKey,T]) Microsoft.FSharp.Collections.MapModule: Microsoft.FSharp.Core.FSharpOption`1[TResult] TryPick[TKey,T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[TKey,Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpOption`1[TResult]]], Microsoft.FSharp.Collections.FSharpMap`2[TKey,T]) Microsoft.FSharp.Collections.MapModule: Microsoft.FSharp.Core.FSharpOption`1[T] TryFind[TKey,T](TKey, Microsoft.FSharp.Collections.FSharpMap`2[TKey,T]) +Microsoft.FSharp.Collections.MapModule: Microsoft.FSharp.Core.FSharpValueOption`1[TResult] TryPickV[TKey,T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[TKey,Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpValueOption`1[TResult]]], Microsoft.FSharp.Collections.FSharpMap`2[TKey,T]) Microsoft.FSharp.Collections.MapModule: System.Collections.Generic.IEnumerable`1[System.Tuple`2[TKey,T]] ToSeq[TKey,T](Microsoft.FSharp.Collections.FSharpMap`2[TKey,T]) Microsoft.FSharp.Collections.MapModule: System.String ToString() Microsoft.FSharp.Collections.MapModule: System.Tuple`2[Microsoft.FSharp.Collections.FSharpMap`2[TKey,T],Microsoft.FSharp.Collections.FSharpMap`2[TKey,T]] Partition[TKey,T](Microsoft.FSharp.Core.FSharpFunc`2[TKey,Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean]], Microsoft.FSharp.Collections.FSharpMap`2[TKey,T]) @@ -413,6 +422,7 @@ Microsoft.FSharp.Collections.MapModule: System.Tuple`2[TKey,T][] ToArray[TKey,T] Microsoft.FSharp.Collections.MapModule: System.Type GetType() Microsoft.FSharp.Collections.MapModule: T Find[TKey,T](TKey, Microsoft.FSharp.Collections.FSharpMap`2[TKey,T]) Microsoft.FSharp.Collections.MapModule: TKey FindKey[TKey,T](Microsoft.FSharp.Core.FSharpFunc`2[TKey,Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean]], Microsoft.FSharp.Collections.FSharpMap`2[TKey,T]) +Microsoft.FSharp.Collections.MapModule: TResult PickV[TKey,T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[TKey,Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpValueOption`1[TResult]]], Microsoft.FSharp.Collections.FSharpMap`2[TKey,T]) Microsoft.FSharp.Collections.MapModule: TResult Pick[TKey,T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[TKey,Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpOption`1[TResult]]], Microsoft.FSharp.Collections.FSharpMap`2[TKey,T]) Microsoft.FSharp.Collections.MapModule: TState FoldBack[TKey,T,TState](Microsoft.FSharp.Core.FSharpFunc`2[TKey,Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpFunc`2[TState,TState]]], Microsoft.FSharp.Collections.FSharpMap`2[TKey,T], TState) Microsoft.FSharp.Collections.MapModule: TState Fold[TKey,T,TState](Microsoft.FSharp.Core.FSharpFunc`2[TState,Microsoft.FSharp.Core.FSharpFunc`2[TKey,Microsoft.FSharp.Core.FSharpFunc`2[T,TState]]], TState, Microsoft.FSharp.Collections.FSharpMap`2[TKey,T]) @@ -438,6 +448,7 @@ Microsoft.FSharp.Collections.SeqModule: Microsoft.FSharp.Core.FSharpOption`1[T] Microsoft.FSharp.Collections.SeqModule: Microsoft.FSharp.Core.FSharpOption`1[T] TryHead[T](System.Collections.Generic.IEnumerable`1[T]) Microsoft.FSharp.Collections.SeqModule: Microsoft.FSharp.Core.FSharpOption`1[T] TryItem[T](Int32, System.Collections.Generic.IEnumerable`1[T]) Microsoft.FSharp.Collections.SeqModule: Microsoft.FSharp.Core.FSharpOption`1[T] TryLast[T](System.Collections.Generic.IEnumerable`1[T]) +Microsoft.FSharp.Collections.SeqModule: Microsoft.FSharp.Core.FSharpValueOption`1[TResult] TryPickV[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpValueOption`1[TResult]], System.Collections.Generic.IEnumerable`1[T]) Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[System.Collections.Generic.IEnumerable`1[T]] Transpose[TCollection,T](System.Collections.Generic.IEnumerable`1[TCollection]) Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[System.Tuple`2[System.Int32,T]] Indexed[T](System.Collections.Generic.IEnumerable`1[T]) Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[System.Tuple`2[T,T]] Pairwise[T](System.Collections.Generic.IEnumerable`1[T]) @@ -446,6 +457,7 @@ Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1 Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[System.Tuple`2[TKey,System.Collections.Generic.IEnumerable`1[T]]] GroupBy[T,TKey](Microsoft.FSharp.Core.FSharpFunc`2[T,TKey], System.Collections.Generic.IEnumerable`1[T]) Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[System.Tuple`2[TKey,System.Int32]] CountBy[T,TKey](Microsoft.FSharp.Core.FSharpFunc`2[T,TKey], System.Collections.Generic.IEnumerable`1[T]) Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[System.Tuple`3[T1,T2,T3]] Zip3[T1,T2,T3](System.Collections.Generic.IEnumerable`1[T1], System.Collections.Generic.IEnumerable`1[T2], System.Collections.Generic.IEnumerable`1[T3]) +Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[TResult] ChooseV[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpValueOption`1[TResult]], System.Collections.Generic.IEnumerable`1[T]) Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[TResult] Choose[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpOption`1[TResult]], System.Collections.Generic.IEnumerable`1[T]) Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[TResult] Collect[T,TCollection,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TCollection], System.Collections.Generic.IEnumerable`1[T]) Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[TResult] Map2[T1,T2,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T1,Microsoft.FSharp.Core.FSharpFunc`2[T2,TResult]], System.Collections.Generic.IEnumerable`1[T1], System.Collections.Generic.IEnumerable`1[T2]) @@ -488,6 +500,7 @@ Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1 Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] TakeWhile[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], System.Collections.Generic.IEnumerable`1[T]) Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Take[T](Int32, System.Collections.Generic.IEnumerable`1[T]) Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Truncate[T](Int32, System.Collections.Generic.IEnumerable`1[T]) +Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] UnfoldV[TState,T](Microsoft.FSharp.Core.FSharpFunc`2[TState,Microsoft.FSharp.Core.FSharpValueOption`1[System.Tuple`2[T,TState]]], TState) Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Unfold[TState,T](Microsoft.FSharp.Core.FSharpFunc`2[TState,Microsoft.FSharp.Core.FSharpOption`1[System.Tuple`2[T,TState]]], TState) Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Where[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], System.Collections.Generic.IEnumerable`1[T]) Microsoft.FSharp.Collections.SeqModule: System.String ToString() @@ -511,6 +524,7 @@ Microsoft.FSharp.Collections.SeqModule: T ReduceBack[T](Microsoft.FSharp.Core.FS Microsoft.FSharp.Collections.SeqModule: T Reduce[T](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpFunc`2[T,T]], System.Collections.Generic.IEnumerable`1[T]) Microsoft.FSharp.Collections.SeqModule: T Sum[T](System.Collections.Generic.IEnumerable`1[T]) Microsoft.FSharp.Collections.SeqModule: TResult AverageBy[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult], System.Collections.Generic.IEnumerable`1[T]) +Microsoft.FSharp.Collections.SeqModule: TResult PickV[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpValueOption`1[TResult]], System.Collections.Generic.IEnumerable`1[T]) Microsoft.FSharp.Collections.SeqModule: TResult Pick[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpOption`1[TResult]], System.Collections.Generic.IEnumerable`1[T]) Microsoft.FSharp.Collections.SeqModule: TResult SumBy[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult], System.Collections.Generic.IEnumerable`1[T]) Microsoft.FSharp.Collections.SeqModule: TState Fold2[T1,T2,TState](Microsoft.FSharp.Core.FSharpFunc`2[TState,Microsoft.FSharp.Core.FSharpFunc`2[T1,Microsoft.FSharp.Core.FSharpFunc`2[T2,TState]]], TState, System.Collections.Generic.IEnumerable`1[T1], System.Collections.Generic.IEnumerable`1[T2]) @@ -593,6 +607,7 @@ Microsoft.FSharp.Control.CommonExtensions: Void AddToObservable[T](System.IObser Microsoft.FSharp.Control.EventModule: Boolean Equals(System.Object) Microsoft.FSharp.Control.EventModule: Int32 GetHashCode() Microsoft.FSharp.Control.EventModule: Microsoft.FSharp.Control.IEvent`2[Microsoft.FSharp.Control.FSharpHandler`1[System.Tuple`2[T,T]],System.Tuple`2[T,T]] Pairwise[TDel,T](Microsoft.FSharp.Control.IEvent`2[TDel,T]) +Microsoft.FSharp.Control.EventModule: Microsoft.FSharp.Control.IEvent`2[Microsoft.FSharp.Control.FSharpHandler`1[TResult],TResult] ChooseV[T,TResult,TDel](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpValueOption`1[TResult]], Microsoft.FSharp.Control.IEvent`2[TDel,T]) Microsoft.FSharp.Control.EventModule: Microsoft.FSharp.Control.IEvent`2[Microsoft.FSharp.Control.FSharpHandler`1[TResult],TResult] Choose[T,TResult,TDel](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpOption`1[TResult]], Microsoft.FSharp.Control.IEvent`2[TDel,T]) Microsoft.FSharp.Control.EventModule: Microsoft.FSharp.Control.IEvent`2[Microsoft.FSharp.Control.FSharpHandler`1[TResult],TResult] Map[T,TResult,TDel](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult], Microsoft.FSharp.Control.IEvent`2[TDel,T]) Microsoft.FSharp.Control.EventModule: Microsoft.FSharp.Control.IEvent`2[Microsoft.FSharp.Control.FSharpHandler`1[TResult],TResult] Scan[TResult,T,TDel](Microsoft.FSharp.Core.FSharpFunc`2[TResult,Microsoft.FSharp.Core.FSharpFunc`2[T,TResult]], TResult, Microsoft.FSharp.Control.IEvent`2[TDel,T]) @@ -742,6 +757,7 @@ Microsoft.FSharp.Control.ObservableModule: Boolean Equals(System.Object) Microsoft.FSharp.Control.ObservableModule: Int32 GetHashCode() Microsoft.FSharp.Control.ObservableModule: System.IDisposable Subscribe[T](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.Unit], System.IObservable`1[T]) Microsoft.FSharp.Control.ObservableModule: System.IObservable`1[System.Tuple`2[T,T]] Pairwise[T](System.IObservable`1[T]) +Microsoft.FSharp.Control.ObservableModule: System.IObservable`1[TResult] ChooseV[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpValueOption`1[TResult]], System.IObservable`1[T]) Microsoft.FSharp.Control.ObservableModule: System.IObservable`1[TResult] Choose[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpOption`1[TResult]], System.IObservable`1[T]) Microsoft.FSharp.Control.ObservableModule: System.IObservable`1[TResult] Map[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult], System.IObservable`1[T]) Microsoft.FSharp.Control.ObservableModule: System.IObservable`1[TResult] Scan[TResult,T](Microsoft.FSharp.Core.FSharpFunc`2[TResult,Microsoft.FSharp.Core.FSharpFunc`2[T,TResult]], TResult, System.IObservable`1[T]) diff --git a/tests/FSharp.Core.UnitTests/SurfaceArea.net40.fs b/tests/FSharp.Core.UnitTests/SurfaceArea.net40.fs index 16035e67c02..9ec047c023f 100644 --- a/tests/FSharp.Core.UnitTests/SurfaceArea.net40.fs +++ b/tests/FSharp.Core.UnitTests/SurfaceArea.net40.fs @@ -96,6 +96,7 @@ Microsoft.FSharp.Collections.ArrayModule: Microsoft.FSharp.Core.FSharpOption`1[T Microsoft.FSharp.Collections.ArrayModule: Microsoft.FSharp.Core.FSharpOption`1[T] TryHead[T](T[]) Microsoft.FSharp.Collections.ArrayModule: Microsoft.FSharp.Core.FSharpOption`1[T] TryItem[T](Int32, T[]) Microsoft.FSharp.Collections.ArrayModule: Microsoft.FSharp.Core.FSharpOption`1[T] TryLast[T](T[]) +Microsoft.FSharp.Collections.ArrayModule: Microsoft.FSharp.Core.FSharpValueOption`1[TResult] TryPickV[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpValueOption`1[TResult]], T[]) Microsoft.FSharp.Collections.ArrayModule: System.Collections.Generic.IEnumerable`1[T] ToSeq[T](T[]) Microsoft.FSharp.Collections.ArrayModule: System.String ToString() Microsoft.FSharp.Collections.ArrayModule: System.Tuple`2[System.Int32,T][] Indexed[T](T[]) @@ -129,8 +130,10 @@ Microsoft.FSharp.Collections.ArrayModule: T ReduceBack[T](Microsoft.FSharp.Core. Microsoft.FSharp.Collections.ArrayModule: T Reduce[T](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpFunc`2[T,T]], T[]) Microsoft.FSharp.Collections.ArrayModule: T Sum[T](T[]) Microsoft.FSharp.Collections.ArrayModule: TResult AverageBy[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult], T[]) +Microsoft.FSharp.Collections.ArrayModule: TResult PickV[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpValueOption`1[TResult]], T[]) Microsoft.FSharp.Collections.ArrayModule: TResult Pick[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpOption`1[TResult]], T[]) Microsoft.FSharp.Collections.ArrayModule: TResult SumBy[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult], T[]) +Microsoft.FSharp.Collections.ArrayModule: TResult[] ChooseV[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpValueOption`1[TResult]], T[]) Microsoft.FSharp.Collections.ArrayModule: TResult[] Choose[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpOption`1[TResult]], T[]) Microsoft.FSharp.Collections.ArrayModule: TResult[] Collect[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult[]], T[]) Microsoft.FSharp.Collections.ArrayModule: TResult[] Map2[T1,T2,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T1,Microsoft.FSharp.Core.FSharpFunc`2[T2,TResult]], T1[], T2[]) @@ -172,6 +175,7 @@ Microsoft.FSharp.Collections.ArrayModule: T[] Tail[T](T[]) Microsoft.FSharp.Collections.ArrayModule: T[] TakeWhile[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], T[]) Microsoft.FSharp.Collections.ArrayModule: T[] Take[T](Int32, T[]) Microsoft.FSharp.Collections.ArrayModule: T[] Truncate[T](Int32, T[]) +Microsoft.FSharp.Collections.ArrayModule: T[] UnfoldV[T,TState](Microsoft.FSharp.Core.FSharpFunc`2[TState,Microsoft.FSharp.Core.FSharpValueOption`1[System.Tuple`2[T,TState]]], TState) Microsoft.FSharp.Collections.ArrayModule: T[] Unfold[T,TState](Microsoft.FSharp.Core.FSharpFunc`2[TState,Microsoft.FSharp.Core.FSharpOption`1[System.Tuple`2[T,TState]]], TState) Microsoft.FSharp.Collections.ArrayModule: T[] Where[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], T[]) Microsoft.FSharp.Collections.ArrayModule: T[] ZeroCreate[T](Int32) @@ -306,6 +310,7 @@ Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[System.Tuple`2[TKey,Microsoft.FSharp.Collections.FSharpList`1[T]]] GroupBy[T,TKey](Microsoft.FSharp.Core.FSharpFunc`2[T,TKey], Microsoft.FSharp.Collections.FSharpList`1[T]) Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[System.Tuple`2[TKey,System.Int32]] CountBy[T,TKey](Microsoft.FSharp.Core.FSharpFunc`2[T,TKey], Microsoft.FSharp.Collections.FSharpList`1[T]) Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[System.Tuple`3[T1,T2,T3]] Zip3[T1,T2,T3](Microsoft.FSharp.Collections.FSharpList`1[T1], Microsoft.FSharp.Collections.FSharpList`1[T2], Microsoft.FSharp.Collections.FSharpList`1[T3]) +Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[TResult] ChooseV[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpValueOption`1[TResult]], Microsoft.FSharp.Collections.FSharpList`1[T]) Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[TResult] Choose[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpOption`1[TResult]], Microsoft.FSharp.Collections.FSharpList`1[T]) Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[TResult] Collect[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Collections.FSharpList`1[TResult]], Microsoft.FSharp.Collections.FSharpList`1[T]) Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[TResult] Map2[T1,T2,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T1,Microsoft.FSharp.Core.FSharpFunc`2[T2,TResult]], Microsoft.FSharp.Collections.FSharpList`1[T1], Microsoft.FSharp.Collections.FSharpList`1[T2]) @@ -340,6 +345,7 @@ Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] TakeWhile[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], Microsoft.FSharp.Collections.FSharpList`1[T]) Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Take[T](Int32, Microsoft.FSharp.Collections.FSharpList`1[T]) Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Truncate[T](Int32, Microsoft.FSharp.Collections.FSharpList`1[T]) +Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] UnfoldV[T,TState](Microsoft.FSharp.Core.FSharpFunc`2[TState,Microsoft.FSharp.Core.FSharpValueOption`1[System.Tuple`2[T,TState]]], TState) Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Unfold[T,TState](Microsoft.FSharp.Core.FSharpFunc`2[TState,Microsoft.FSharp.Core.FSharpOption`1[System.Tuple`2[T,TState]]], TState) Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Where[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], Microsoft.FSharp.Collections.FSharpList`1[T]) Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Core.FSharpOption`1[System.Int32] TryFindIndexBack[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], Microsoft.FSharp.Collections.FSharpList`1[T]) @@ -350,6 +356,7 @@ Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Core.FSharpOption`1[T] Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Core.FSharpOption`1[T] TryHead[T](Microsoft.FSharp.Collections.FSharpList`1[T]) Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Core.FSharpOption`1[T] TryItem[T](Int32, Microsoft.FSharp.Collections.FSharpList`1[T]) Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Core.FSharpOption`1[T] TryLast[T](Microsoft.FSharp.Collections.FSharpList`1[T]) +Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Core.FSharpValueOption`1[TResult] TryPickV[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpValueOption`1[TResult]], Microsoft.FSharp.Collections.FSharpList`1[T]) Microsoft.FSharp.Collections.ListModule: System.Collections.Generic.IEnumerable`1[T] ToSeq[T](Microsoft.FSharp.Collections.FSharpList`1[T]) Microsoft.FSharp.Collections.ListModule: System.String ToString() Microsoft.FSharp.Collections.ListModule: System.Tuple`2[Microsoft.FSharp.Collections.FSharpList`1[T1],Microsoft.FSharp.Collections.FSharpList`1[T2]] Unzip[T1,T2](Microsoft.FSharp.Collections.FSharpList`1[System.Tuple`2[T1,T2]]) @@ -376,6 +383,7 @@ Microsoft.FSharp.Collections.ListModule: T ReduceBack[T](Microsoft.FSharp.Core.F Microsoft.FSharp.Collections.ListModule: T Reduce[T](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpFunc`2[T,T]], Microsoft.FSharp.Collections.FSharpList`1[T]) Microsoft.FSharp.Collections.ListModule: T Sum[T](Microsoft.FSharp.Collections.FSharpList`1[T]) Microsoft.FSharp.Collections.ListModule: TResult AverageBy[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult], Microsoft.FSharp.Collections.FSharpList`1[T]) +Microsoft.FSharp.Collections.ListModule: TResult PickV[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpValueOption`1[TResult]], Microsoft.FSharp.Collections.FSharpList`1[T]) Microsoft.FSharp.Collections.ListModule: TResult Pick[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpOption`1[TResult]], Microsoft.FSharp.Collections.FSharpList`1[T]) Microsoft.FSharp.Collections.ListModule: TResult SumBy[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult], Microsoft.FSharp.Collections.FSharpList`1[T]) Microsoft.FSharp.Collections.ListModule: TState Fold2[T1,T2,TState](Microsoft.FSharp.Core.FSharpFunc`2[TState,Microsoft.FSharp.Core.FSharpFunc`2[T1,Microsoft.FSharp.Core.FSharpFunc`2[T2,TState]]], TState, Microsoft.FSharp.Collections.FSharpList`1[T1], Microsoft.FSharp.Collections.FSharpList`1[T2]) @@ -406,6 +414,7 @@ Microsoft.FSharp.Collections.MapModule: Microsoft.FSharp.Collections.FSharpMap`2 Microsoft.FSharp.Collections.MapModule: Microsoft.FSharp.Core.FSharpOption`1[TKey] TryFindKey[TKey,T](Microsoft.FSharp.Core.FSharpFunc`2[TKey,Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean]], Microsoft.FSharp.Collections.FSharpMap`2[TKey,T]) Microsoft.FSharp.Collections.MapModule: Microsoft.FSharp.Core.FSharpOption`1[TResult] TryPick[TKey,T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[TKey,Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpOption`1[TResult]]], Microsoft.FSharp.Collections.FSharpMap`2[TKey,T]) Microsoft.FSharp.Collections.MapModule: Microsoft.FSharp.Core.FSharpOption`1[T] TryFind[TKey,T](TKey, Microsoft.FSharp.Collections.FSharpMap`2[TKey,T]) +Microsoft.FSharp.Collections.MapModule: Microsoft.FSharp.Core.FSharpValueOption`1[TResult] TryPickV[TKey,T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[TKey,Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpValueOption`1[TResult]]], Microsoft.FSharp.Collections.FSharpMap`2[TKey,T]) Microsoft.FSharp.Collections.MapModule: System.Collections.Generic.IEnumerable`1[System.Tuple`2[TKey,T]] ToSeq[TKey,T](Microsoft.FSharp.Collections.FSharpMap`2[TKey,T]) Microsoft.FSharp.Collections.MapModule: System.String ToString() Microsoft.FSharp.Collections.MapModule: System.Tuple`2[Microsoft.FSharp.Collections.FSharpMap`2[TKey,T],Microsoft.FSharp.Collections.FSharpMap`2[TKey,T]] Partition[TKey,T](Microsoft.FSharp.Core.FSharpFunc`2[TKey,Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean]], Microsoft.FSharp.Collections.FSharpMap`2[TKey,T]) @@ -413,6 +422,7 @@ Microsoft.FSharp.Collections.MapModule: System.Tuple`2[TKey,T][] ToArray[TKey,T] Microsoft.FSharp.Collections.MapModule: System.Type GetType() Microsoft.FSharp.Collections.MapModule: T Find[TKey,T](TKey, Microsoft.FSharp.Collections.FSharpMap`2[TKey,T]) Microsoft.FSharp.Collections.MapModule: TKey FindKey[TKey,T](Microsoft.FSharp.Core.FSharpFunc`2[TKey,Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean]], Microsoft.FSharp.Collections.FSharpMap`2[TKey,T]) +Microsoft.FSharp.Collections.MapModule: TResult PickV[TKey,T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[TKey,Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpValueOption`1[TResult]]], Microsoft.FSharp.Collections.FSharpMap`2[TKey,T]) Microsoft.FSharp.Collections.MapModule: TResult Pick[TKey,T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[TKey,Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpOption`1[TResult]]], Microsoft.FSharp.Collections.FSharpMap`2[TKey,T]) Microsoft.FSharp.Collections.MapModule: TState FoldBack[TKey,T,TState](Microsoft.FSharp.Core.FSharpFunc`2[TKey,Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpFunc`2[TState,TState]]], Microsoft.FSharp.Collections.FSharpMap`2[TKey,T], TState) Microsoft.FSharp.Collections.MapModule: TState Fold[TKey,T,TState](Microsoft.FSharp.Core.FSharpFunc`2[TState,Microsoft.FSharp.Core.FSharpFunc`2[TKey,Microsoft.FSharp.Core.FSharpFunc`2[T,TState]]], TState, Microsoft.FSharp.Collections.FSharpMap`2[TKey,T]) @@ -438,6 +448,7 @@ Microsoft.FSharp.Collections.SeqModule: Microsoft.FSharp.Core.FSharpOption`1[T] Microsoft.FSharp.Collections.SeqModule: Microsoft.FSharp.Core.FSharpOption`1[T] TryHead[T](System.Collections.Generic.IEnumerable`1[T]) Microsoft.FSharp.Collections.SeqModule: Microsoft.FSharp.Core.FSharpOption`1[T] TryItem[T](Int32, System.Collections.Generic.IEnumerable`1[T]) Microsoft.FSharp.Collections.SeqModule: Microsoft.FSharp.Core.FSharpOption`1[T] TryLast[T](System.Collections.Generic.IEnumerable`1[T]) +Microsoft.FSharp.Collections.SeqModule: Microsoft.FSharp.Core.FSharpValueOption`1[TResult] TryPickV[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpValueOption`1[TResult]], System.Collections.Generic.IEnumerable`1[T]) Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[System.Collections.Generic.IEnumerable`1[T]] Transpose[TCollection,T](System.Collections.Generic.IEnumerable`1[TCollection]) Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[System.Tuple`2[System.Int32,T]] Indexed[T](System.Collections.Generic.IEnumerable`1[T]) Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[System.Tuple`2[T,T]] Pairwise[T](System.Collections.Generic.IEnumerable`1[T]) @@ -446,6 +457,7 @@ Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1 Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[System.Tuple`2[TKey,System.Collections.Generic.IEnumerable`1[T]]] GroupBy[T,TKey](Microsoft.FSharp.Core.FSharpFunc`2[T,TKey], System.Collections.Generic.IEnumerable`1[T]) Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[System.Tuple`2[TKey,System.Int32]] CountBy[T,TKey](Microsoft.FSharp.Core.FSharpFunc`2[T,TKey], System.Collections.Generic.IEnumerable`1[T]) Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[System.Tuple`3[T1,T2,T3]] Zip3[T1,T2,T3](System.Collections.Generic.IEnumerable`1[T1], System.Collections.Generic.IEnumerable`1[T2], System.Collections.Generic.IEnumerable`1[T3]) +Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[TResult] ChooseV[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpValueOption`1[TResult]], System.Collections.Generic.IEnumerable`1[T]) Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[TResult] Choose[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpOption`1[TResult]], System.Collections.Generic.IEnumerable`1[T]) Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[TResult] Collect[T,TCollection,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TCollection], System.Collections.Generic.IEnumerable`1[T]) Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[TResult] Map2[T1,T2,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T1,Microsoft.FSharp.Core.FSharpFunc`2[T2,TResult]], System.Collections.Generic.IEnumerable`1[T1], System.Collections.Generic.IEnumerable`1[T2]) @@ -488,6 +500,7 @@ Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1 Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] TakeWhile[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], System.Collections.Generic.IEnumerable`1[T]) Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Take[T](Int32, System.Collections.Generic.IEnumerable`1[T]) Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Truncate[T](Int32, System.Collections.Generic.IEnumerable`1[T]) +Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] UnfoldV[TState,T](Microsoft.FSharp.Core.FSharpFunc`2[TState,Microsoft.FSharp.Core.FSharpValueOption`1[System.Tuple`2[T,TState]]], TState) Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Unfold[TState,T](Microsoft.FSharp.Core.FSharpFunc`2[TState,Microsoft.FSharp.Core.FSharpOption`1[System.Tuple`2[T,TState]]], TState) Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Where[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], System.Collections.Generic.IEnumerable`1[T]) Microsoft.FSharp.Collections.SeqModule: System.String ToString() @@ -511,6 +524,7 @@ Microsoft.FSharp.Collections.SeqModule: T ReduceBack[T](Microsoft.FSharp.Core.FS Microsoft.FSharp.Collections.SeqModule: T Reduce[T](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpFunc`2[T,T]], System.Collections.Generic.IEnumerable`1[T]) Microsoft.FSharp.Collections.SeqModule: T Sum[T](System.Collections.Generic.IEnumerable`1[T]) Microsoft.FSharp.Collections.SeqModule: TResult AverageBy[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult], System.Collections.Generic.IEnumerable`1[T]) +Microsoft.FSharp.Collections.SeqModule: TResult PickV[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpValueOption`1[TResult]], System.Collections.Generic.IEnumerable`1[T]) Microsoft.FSharp.Collections.SeqModule: TResult Pick[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpOption`1[TResult]], System.Collections.Generic.IEnumerable`1[T]) Microsoft.FSharp.Collections.SeqModule: TResult SumBy[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult], System.Collections.Generic.IEnumerable`1[T]) Microsoft.FSharp.Collections.SeqModule: TState Fold2[T1,T2,TState](Microsoft.FSharp.Core.FSharpFunc`2[TState,Microsoft.FSharp.Core.FSharpFunc`2[T1,Microsoft.FSharp.Core.FSharpFunc`2[T2,TState]]], TState, System.Collections.Generic.IEnumerable`1[T1], System.Collections.Generic.IEnumerable`1[T2]) @@ -593,6 +607,7 @@ Microsoft.FSharp.Control.CommonExtensions: Void AddToObservable[T](System.IObser Microsoft.FSharp.Control.EventModule: Boolean Equals(System.Object) Microsoft.FSharp.Control.EventModule: Int32 GetHashCode() Microsoft.FSharp.Control.EventModule: Microsoft.FSharp.Control.IEvent`2[Microsoft.FSharp.Control.FSharpHandler`1[System.Tuple`2[T,T]],System.Tuple`2[T,T]] Pairwise[TDel,T](Microsoft.FSharp.Control.IEvent`2[TDel,T]) +Microsoft.FSharp.Control.EventModule: Microsoft.FSharp.Control.IEvent`2[Microsoft.FSharp.Control.FSharpHandler`1[TResult],TResult] ChooseV[T,TResult,TDel](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpValueOption`1[TResult]], Microsoft.FSharp.Control.IEvent`2[TDel,T]) Microsoft.FSharp.Control.EventModule: Microsoft.FSharp.Control.IEvent`2[Microsoft.FSharp.Control.FSharpHandler`1[TResult],TResult] Choose[T,TResult,TDel](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpOption`1[TResult]], Microsoft.FSharp.Control.IEvent`2[TDel,T]) Microsoft.FSharp.Control.EventModule: Microsoft.FSharp.Control.IEvent`2[Microsoft.FSharp.Control.FSharpHandler`1[TResult],TResult] Map[T,TResult,TDel](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult], Microsoft.FSharp.Control.IEvent`2[TDel,T]) Microsoft.FSharp.Control.EventModule: Microsoft.FSharp.Control.IEvent`2[Microsoft.FSharp.Control.FSharpHandler`1[TResult],TResult] Scan[TResult,T,TDel](Microsoft.FSharp.Core.FSharpFunc`2[TResult,Microsoft.FSharp.Core.FSharpFunc`2[T,TResult]], TResult, Microsoft.FSharp.Control.IEvent`2[TDel,T]) @@ -742,6 +757,7 @@ Microsoft.FSharp.Control.ObservableModule: Boolean Equals(System.Object) Microsoft.FSharp.Control.ObservableModule: Int32 GetHashCode() Microsoft.FSharp.Control.ObservableModule: System.IDisposable Subscribe[T](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.Unit], System.IObservable`1[T]) Microsoft.FSharp.Control.ObservableModule: System.IObservable`1[System.Tuple`2[T,T]] Pairwise[T](System.IObservable`1[T]) +Microsoft.FSharp.Control.ObservableModule: System.IObservable`1[TResult] ChooseV[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpValueOption`1[TResult]], System.IObservable`1[T]) Microsoft.FSharp.Control.ObservableModule: System.IObservable`1[TResult] Choose[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpOption`1[TResult]], System.IObservable`1[T]) Microsoft.FSharp.Control.ObservableModule: System.IObservable`1[TResult] Map[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult], System.IObservable`1[T]) Microsoft.FSharp.Control.ObservableModule: System.IObservable`1[TResult] Scan[TResult,T](Microsoft.FSharp.Core.FSharpFunc`2[TResult,Microsoft.FSharp.Core.FSharpFunc`2[T,TResult]], TResult, System.IObservable`1[T]) diff --git a/tests/fsharp/perf/ValueOption/ValueOption.sln b/tests/fsharp/perf/ValueOption/ValueOption.sln new file mode 100644 index 00000000000..49c1d399340 --- /dev/null +++ b/tests/fsharp/perf/ValueOption/ValueOption.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29009.5 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "ValueOption", "ValueOption\ValueOption.fsproj", "{9B0B5493-1957-49B6-AC99-E6FAD14AD4CC}" +EndProject +Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FSharp.Core", "..\..\..\..\src\fsharp\FSharp.Core\FSharp.Core.fsproj", "{6AD3938C-E325-4651-9952-B5BBE1E46660}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9B0B5493-1957-49B6-AC99-E6FAD14AD4CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9B0B5493-1957-49B6-AC99-E6FAD14AD4CC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9B0B5493-1957-49B6-AC99-E6FAD14AD4CC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9B0B5493-1957-49B6-AC99-E6FAD14AD4CC}.Release|Any CPU.Build.0 = Release|Any CPU + {6AD3938C-E325-4651-9952-B5BBE1E46660}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6AD3938C-E325-4651-9952-B5BBE1E46660}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6AD3938C-E325-4651-9952-B5BBE1E46660}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6AD3938C-E325-4651-9952-B5BBE1E46660}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {29BD8449-EA3F-4AD2-BF78-197FECB5BA70} + EndGlobalSection +EndGlobal diff --git a/tests/fsharp/perf/ValueOption/ValueOption/Program.fs b/tests/fsharp/perf/ValueOption/ValueOption/Program.fs new file mode 100644 index 00000000000..44c38c12cd0 --- /dev/null +++ b/tests/fsharp/perf/ValueOption/ValueOption/Program.fs @@ -0,0 +1,216 @@ +open BenchmarkDotNet.Attributes +open BenchmarkDotNet.Running + +type Record = { + Int: int + String: string + Children: Record list +} + +let createRecord i = + { Int = i + String = string i + Children = [ + { Int = i + String = string i + Children = [] } + ] } + + +[] +type List_choose() = + + [] + [] val mutable N : int + + [] + [] val mutable Type : string + + [] val mutable ints : int list + [] val mutable recs : Record list + + [] + member this.Setup () = + this.ints <- [1 .. this.N] + this.recs <- List.init this.N createRecord + + [] + member this.Option () = + match this.Type with + | "int" -> this.ints |> List.choose (fun x -> Some x) |> ignore + | "record" -> this.recs |> List.choose (fun x -> Some x) |> ignore + | _ -> failwith "Should never happen" + + [] + member this.ValueOption () = + match this.Type with + | "int" -> this.ints |> List.chooseV (fun x -> ValueSome x) |> ignore + | "record" -> this.recs |> List.chooseV (fun x -> ValueSome x) |> ignore + | _ -> failwith "Should never happen" + + +[] +type List_tryPick() = + + [] + [] val mutable N : int + + [] + [] val mutable Type : string + + [] val mutable ints : int list + [] val mutable recs : Record list + + [] + member this.Setup () = + this.ints <- [1 .. this.N] + this.recs <- List.init this.N createRecord + + [] + member this.Option () = + match this.Type with + | "int" -> this.ints |> List.tryPick (fun x -> None) |> ignore + | "record" -> this.recs |> List.tryPick (fun x -> None) |> ignore + | _ -> failwith "Should never happen" + + [] + member this.ValueOption () = + match this.Type with + | "int" -> this.ints |> List.tryPickV (fun x -> ValueNone) |> ignore + | "record" -> this.recs |> List.tryPickV (fun x -> ValueNone) |> ignore + | _ -> failwith "Should never happen" + + +[] +type List_unfoldV() = + + [] + [] val mutable N : int + + [] + [] val mutable Type : string + + [] + member this.Option () = + match this.Type with + | "int" -> + List.unfold (fun i -> if i > this.N then None else Some (i, (i + 1))) 0 + |> ignore + | "record" -> + List.unfold (fun i -> if i > this.N then None else Some (createRecord i, (i + 1))) 0 + |> ignore + | _ -> failwith "Should never happen" + + [] + member this.ValueOption () = + match this.Type with + | "int" -> + List.unfoldV (fun i -> if i > this.N then ValueNone else ValueSome (i, (i + 1))) 0 + |> ignore + | "record" -> + List.unfoldV (fun i -> if i > this.N then ValueNone else ValueSome (createRecord i, (i + 1))) 0 + |> ignore + | _ -> failwith "Should never happen" + + +[] +type Array_choose() = + + [] + [] val mutable N : int + + [] + [] val mutable Type : string + + [] val mutable ints : int array + [] val mutable recs : Record array + + [] + member this.Setup () = + this.ints <- [|1 .. this.N|] + this.recs <- Array.init this.N createRecord + + [] + member this.Option () = + match this.Type with + | "int" -> this.ints |> Array.choose (fun x -> Some x) |> ignore + | "record" -> this.recs |> Array.choose (fun x -> Some x) |> ignore + | _ -> failwith "Should never happen" + + [] + member this.ValueOption () = + match this.Type with + | "int" -> this.ints |> Array.chooseV (fun x -> ValueSome x) |> ignore + | "record" -> this.recs |> Array.chooseV (fun x -> ValueSome x) |> ignore + | _ -> failwith "Should never happen" + + +[] +type Array_tryPick() = + + [] + [] val mutable N : int + + [] + [] val mutable Type : string + + [] val mutable ints : int array + [] val mutable recs : Record array + + [] + member this.Setup () = + this.ints <- [|1 .. this.N|] + this.recs <- Array.init this.N createRecord + + [] + member this.Option () = + match this.Type with + | "int" -> this.ints |> Array.tryPick (fun x -> None) |> ignore + | "record" -> this.recs |> Array.tryPick (fun x -> None) |> ignore + | _ -> failwith "Should never happen" + + [] + member this.ValueOption () = + match this.Type with + | "int" -> this.ints |> Array.tryPickV (fun x -> ValueNone) |> ignore + | "record" -> this.recs |> Array.tryPickV (fun x -> ValueNone) |> ignore + | _ -> failwith "Should never happen" + + +[] +type Array_unfoldV() = + + [] + [] val mutable N : int + + [] + [] val mutable Type : string + + [] + member this.Option () = + match this.Type with + | "int" -> + Array.unfold (fun i -> if i > this.N then None else Some (i, (i + 1))) 0 + |> ignore + | "record" -> + Array.unfold (fun i -> if i > this.N then None else Some (createRecord i, (i + 1))) 0 + |> ignore + | _ -> failwith "Should never happen" + + [] + member this.ValueOption () = + match this.Type with + | "int" -> + Array.unfoldV (fun i -> if i > this.N then ValueNone else ValueSome (i, (i + 1))) 0 + |> ignore + | "record" -> + Array.unfoldV (fun i -> if i > this.N then ValueNone else ValueSome (createRecord i, (i + 1))) 0 + |> ignore + | _ -> failwith "Should never happen" + + +[] +let main argv = + let summaries = BenchmarkRunner.Run(typeof.Assembly) + printfn "%A" summaries + 0 diff --git a/tests/fsharp/perf/ValueOption/ValueOption/ValueOption.fsproj b/tests/fsharp/perf/ValueOption/ValueOption/ValueOption.fsproj new file mode 100644 index 00000000000..795602e4ad1 --- /dev/null +++ b/tests/fsharp/perf/ValueOption/ValueOption/ValueOption.fsproj @@ -0,0 +1,20 @@ + + + + Exe + netcoreapp3.0 + + + + + + + + + + + + + + +