Skip to content

Commit de147f7

Browse files
authored
+ test for SeqT
1 parent 44369ed commit de147f7

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

tests/FSharpPlus.Tests/SeqT.fs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,36 @@ module BasicTests =
106106
let y = (fn |> SeqT.run |> Reader.run) -1 |> Seq.toList
107107
areEqual [] y
108108

109+
#nowarn "0025"
110+
111+
module WellBehaved =
112+
// from https://wiki.haskell.org/ListT_done_right
113+
114+
[<Test>]
115+
let orderOfPrinting () =
116+
let putCharIntoMutable (m: ref<string>) (x: char) = async { m.Value <- m.Value + sprintf "%c" x }
117+
118+
let m = ref ""
119+
let [a;b;c] : SeqT<Async<bool>, unit> list = map (liftAsync << putCharIntoMutable m) ['a'; 'b'; 'c']
120+
let t1 = ((a <|> a) *> b) *> c |> SeqT.run |> Async.RunSynchronously
121+
let m1 = m.Value
122+
m.Value <- ""
123+
let t2 = (a <|> a) *> (b *> c) |> SeqT.run |> Async.RunSynchronously
124+
let m2 = m.Value
125+
126+
areEqual m1 "abcabc"
127+
areEqual m1 m2
128+
129+
[<Test>]
130+
let ``Order of ListT []`` () =
131+
let v = function
132+
| 0 -> SeqT [seq [0 ; 1]]
133+
| 1 -> SeqT [seq [0]; [1]]
134+
135+
let r1 = SeqT.run <| ((v >=> v) >=> v) 0
136+
let r2 = SeqT.run <| (v >=> (v >=> v)) 0
137+
areEqual (List.map toList r1) ([[0; 1; 1; 1]; [0; 1; 1; 1]; [0; 1; 1; 1]; [0; 1; 1; 1]; [0; 1; 1; 1]])
138+
areEqual (List.map toList r1) (List.map toList r2)
109139

110140
module ComputationExpressions =
111141

@@ -324,5 +354,3 @@ module Applicative =
324354
let actual = SeqT.map2M (fun a b -> a + b |> async.Return) a b
325355
let expected = Seq.zip la lb |> Seq.map ((<||) (+)) |> SeqT.ofSeq
326356
Assert.True (EQ expected actual)
327-
328-

0 commit comments

Comments
 (0)