11module FSharpPlus.Tests.Helpers
22
3- open NUnit. Framework
3+ open System
44open System.Collections
5+ open NUnit.Framework
6+ open FSharpPlus
7+ open FSharpPlus.Control
58
69let areEqual ( x : 't ) ( y : 't ) = Assert.AreEqual ( x, y)
710let areStEqual x y = Assert.IsTrue( ( x = y), sprintf " Expected %A to be structurally equal to %A " x y)
@@ -14,3 +17,61 @@ module SideEffects =
1417 let add x = effects.Add ( x)
1518 let get () = effects |> Seq.toList
1619 let are lst = areEquivalent lst ( get ())
20+
21+
22+ type WrappedListD < 's > = WrappedListD of 's list with
23+ interface Collections.Generic.IEnumerable< 's> with member x.GetEnumerator () = ( let ( WrappedListD x ) = x in x :> _ seq) .GetEnumerator ()
24+ interface Collections.IEnumerable with member x.GetEnumerator () = ( let ( WrappedListD x ) = x in x :> _ seq) .GetEnumerator () :> Collections.IEnumerator
25+ static member Return ( x ) = SideEffects.add " Using WrappedListD's Return" ; WrappedListD [ x]
26+ static member (>>= ) (( WrappedListD x): WrappedListD< 'T>, f) = SideEffects.add " Using WrappedListD's Bind" ; WrappedListD ( List.collect ( f >> ( fun ( WrappedListD x ) -> x)) x)
27+ static member inline FoldMap ( WrappedListD x , f ) =
28+ SideEffects.add " Using optimized foldMap"
29+ Seq.fold ( fun x y -> x ++ ( f y)) zero x
30+ static member Zip ( WrappedListD x , WrappedListD y ) = SideEffects.add " Using WrappedListD's zip" ; WrappedListD ( List.zip x y)
31+ static member Exists ( x , f ) =
32+ SideEffects.add " Using WrappedListD's Exists"
33+ let ( WrappedListD lst ) = x
34+ List.exists f lst
35+ static member Pick ( x , f ) =
36+ SideEffects.add " Using WrappedListD's Pick"
37+ let ( WrappedListD lst ) = x
38+ List.pick f lst
39+ static member Min x =
40+ SideEffects.add " Using WrappedListD's Min"
41+ let ( WrappedListD lst ) = x
42+ List.min lst
43+ static member MaxBy ( x , f ) =
44+ SideEffects.add " Using WrappedListD's MaxBy"
45+ let ( WrappedListD lst ) = x
46+ List.maxBy f lst
47+ static member MapIndexed ( WrappedListD x , f ) =
48+ SideEffects.add " Using WrappedListD's MapIndexed"
49+ WrappedListD ( List.mapi f x)
50+ static member ChooseIndexed ( WrappedListD x , f ) =
51+ SideEffects.add " Using WrappedListD's ChooseIndexed"
52+ WrappedListD ( List.choosei f x)
53+ static member Lift3 ( f , WrappedListD x , WrappedListD y , WrappedListD z ) =
54+ SideEffects.add " Using WrappedListD's Lift3"
55+ WrappedListD ( List.lift3 f x y z)
56+ static member IterateIndexed ( WrappedListD x , f ) =
57+ SideEffects.add " Using WrappedListD's IterateIndexed"
58+ List.iteri f x
59+ static member inline FoldIndexed ( WrappedListD x , f , z ) =
60+ SideEffects.add " Using WrappedListD's FoldIndexed"
61+ foldi f z x
62+ static member inline TraverseIndexed ( WrappedListD x , f ) =
63+ SideEffects.add " Using WrappedListD's TraverseIndexed"
64+ WrappedListD <!> ( traversei f x : ^r )
65+ static member FindIndex ( WrappedListD x , y ) =
66+ SideEffects.add " Using WrappedListD's FindIndex"
67+ findIndex y x
68+ static member FindSliceIndex ( WrappedListD x , WrappedListD y ) =
69+ SideEffects.add " Using WrappedListD's FindSliceIndex"
70+ findSliceIndex y x
71+ static member FindLastSliceIndex ( WrappedListD x , WrappedListD y ) =
72+ SideEffects.add " Using WrappedListD's FindLastSliceIndex"
73+ findLastSliceIndex y x
74+ member this.Length =
75+ SideEffects.add " Using WrappedListD's Length"
76+ let ( WrappedListD lst ) = this
77+ List.length lst
0 commit comments