From c86c1759f1180aebbeedd2bf7e9a64c65c9360c3 Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Fri, 19 Jun 2015 17:50:25 +0200 Subject: [PATCH] mapFold works like map + fold --- .../ListProperties.fs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/fsharp/FSharp.Core.PropertyTests/ListProperties.fs b/src/fsharp/FSharp.Core.PropertyTests/ListProperties.fs index 4b502732ca3..39444b65a26 100644 --- a/src/fsharp/FSharp.Core.PropertyTests/ListProperties.fs +++ b/src/fsharp/FSharp.Core.PropertyTests/ListProperties.fs @@ -184,6 +184,24 @@ let ``list isEmpty if and only if length is 0`` () = Check.QuickThrowOnFailure length_and_isEmpty Check.QuickThrowOnFailure length_and_isEmpty + +let mapFold_and_map_and_fold<'a when 'a : comparison> (xs : list<'a>) mapF foldF start = + let f s x = + let x' = mapF x + let s' = foldF s x' + x',s' + + let a,ar = xs |> List.mapFold f start + let b = xs |> List.map mapF + let br = b |> List.fold foldF start + a = b && ar = br + +[] +let ``mapFold works like map + fold`` () = + Check.QuickThrowOnFailure mapFold_and_map_and_fold + Check.QuickThrowOnFailure mapFold_and_map_and_fold + Check.QuickThrowOnFailure mapFold_and_map_and_fold + let findBack_and_exists<'a when 'a : comparison> (xs : list<'a>) f = let a = try