Skip to content

Revert "List.fold/contains simplification" #3979

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions src/fsharp/FSharp.Core/list.fs
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,15 @@ namespace Microsoft.FSharp.Collections

[<CompiledName("Fold")>]
let fold<'T,'State> folder (state:'State) (list: 'T list) =
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(folder)
let mutable acc = state
for x in list do
acc <- f.Invoke(acc, x)
acc
match list with
| [] -> state
| _ ->
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(folder)
let rec loop s xs =
match xs with
| [] -> s
| h::t -> loop (f.Invoke(s,h)) t
loop state list

[<CompiledName("Pairwise")>]
let pairwise (list: 'T list) =
Expand Down Expand Up @@ -352,10 +356,12 @@ namespace Microsoft.FSharp.Collections
let exists predicate list = Microsoft.FSharp.Primitives.Basics.List.exists predicate list

[<CompiledName("Contains")>]
let rec contains value source =
match source with
| [] -> false
| h::t -> if h = value then true else contains value t
let inline contains value source =
let rec contains e xs1 =
match xs1 with
| [] -> false
| h1::t1 -> e = h1 || contains e t1
contains value source

let rec exists2aux (f:OptimizedClosures.FSharpFunc<_,_,_>) list1 list2 =
match list1,list2 with
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/FSharp.Core/list.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ namespace Microsoft.FSharp.Collections
/// <param name="source">The input list.</param>
/// <returns>True if the input list contains the specified element; false otherwise.</returns>
[<CompiledName("Contains")>]
val contains: value:'T -> source:'T list -> bool when 'T : equality
val inline contains: value:'T -> source:'T list -> bool when 'T : equality

/// <summary>Returns a list that contains no duplicate entries according to generic hash and
/// equality comparisons on the entries.
Expand Down