Skip to content

Commit 0e93ae9

Browse files
committed
Add test for Lift3 for Free.
1 parent c3c3813 commit 0e93ae9

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tests/FSharpPlus.Tests/Free.fs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,3 +316,39 @@ module Fold =
316316
|> Identity.run
317317

318318
areStEqual (Ok { Id = FooId "1"; Name = "test" }) response
319+
320+
module Lift3 =
321+
322+
type Instruction<'next> =
323+
| Read of int * (string -> 'next)
324+
static member Map(i, f) =
325+
match i with
326+
| Read (x, next) -> Read(x, next >> f)
327+
328+
let read x = Read(x, id) |> Free.liftF
329+
330+
type ApplicativeBuilder<'a>() =
331+
inherit MonadFxStrictBuilder<'a>()
332+
333+
member inline _.BindReturn(x, f) = map f x
334+
335+
let applicative<'a> = ApplicativeBuilder<'a>()
336+
337+
[<Test>]
338+
let ``should be able to use applicative CE which requires Lift3`` () =
339+
let program =
340+
applicative {
341+
let! a = read 1
342+
and! b = read 2
343+
and! c = read 3
344+
return a, b, c
345+
}
346+
347+
let result =
348+
program
349+
|> Free.fold
350+
(function
351+
| Read (i, next) -> i |> string |> next |> result)
352+
|> Identity.run
353+
354+
areStEqual result ("1", "2", "3")

0 commit comments

Comments
 (0)