@@ -120,52 +120,37 @@ let collect n =
120120//run bindUnfold
121121//run collect
122122
123- let rec prependToAll ( a : 'a ) ( ls : 'a list ) : 'a list =
124- match ls with
125- | [] -> []
126- | hd:: tl -> a:: hd:: prependToAll a tl
127-
128- let rec intersperse ( a : 'a ) ( ls : 'a list ) : 'a list =
129- match ls with
130- | [] -> []
131- | hd:: tl -> hd:: prependToAll a tl
123+ let Y = Choice1Of2
124+ let S = Choice2Of2
125+
126+ let timeMs = 500
132127
133- let intercalate ( l : 'a list ) ( xs : 'a list list ) : 'a list =
134- intersperse l xs |> List.concat
128+ let inp0 = [ ]
129+ let exp0 = [ ]
135130
136- let batch ( size : int ) ( ls : 'a list ) : 'a list list =
137- let rec go batch ls =
138- match ls with
139- | [] -> [ List.rev batch]
140- | _ when List.length batch = size -> ( List.rev batch):: go [] ls
141- | hd:: tl -> go ( hd:: batch) tl
142- go [] ls
131+ let inp1 = [ Y 1 ; Y 2 ; S timeMs ; Y 3 ; Y 4 ; S timeMs ; Y 5 ; Y 6 ]
132+ let exp1 = [ [ 1 ; 2 ] ; [ 3 ; 4 ] ; [ 5 ; 6 ] ]
143133
144-
145- let Y = Choice1Of2
146- let S = Choice2Of2
147- let sleepMs = 100
134+ // let inp2 : Choice<int, int> list = [ S 500 ]
135+ // let exp2 : int list list = [ [] ; [] ; [] ; [] ]
148136
149137let toSeq ( xs : Choice < int , int > list ) = asyncSeq {
150138 for x in xs do
151139 match x with
152140 | Choice1Of2 v -> yield v
153- | Choice2Of2 s -> do ! Async.Sleep s }
141+ | Choice2Of2 s -> do ! Async.Sleep s }
154142
155- for ( size , batchSize ) in [ ( 0 , 0 ) ; ( 10 , 2 ) ; ( 30 , 2 ) ] do
143+ for ( inp , exp ) in [ ( inp0 , exp0 ) ; ( inp1 , exp1 ) ] do
156144
157- let expected =
158- List.init size id
159- |> batch batchSize
160-
161145 let actual =
162- expected
163- |> List.map ( List.map Y)
164- |> intercalate [ S sleepMs]
165- |> toSeq
166- |> AsyncSeq.bufferByTime sleepMs
146+ toSeq inp
147+ |> AsyncSeq.bufferByTime ( timeMs - 5 )
167148 |> AsyncSeq.map List.ofArray
168149 |> AsyncSeq.toList
150+
151+ printfn " actual=%A expected=%A " actual exp
152+
153+ //let ls = toSeq inp |> AsyncSeq.toList
154+ //let actualLs = actual |> List.concat
169155
170- //Assert.True ((actual = expected))
171- printfn " actual=%A expected=%A " actual expected
156+
0 commit comments