如何在 f# 中将 Result<'a,'b> 映射到 Reader<Result<'a,'b>?

How to map Result<'a,'b> to Reader<Result<'a,'b> in f#?

我有将函数映射到 "Reader-Result" 的函数,其中 f 是 'a->'b: ('a->'b) -> Reader<Result<'a,'c>> -> Reader<Result<'b,'c>>

let map f = Reader.map <| Result.map f

但是如何编写一个将函数 'a->Result<'b,'c> 作为输入的类似映射?

类似于 map 但其参数 returns 和 Result<_,_> 的函数称为 bind。它的签名是:

bind : ('a -> Result<'b, 'c>) -> Result<'a, 'c> -> Result<'b, 'c>

我假设你想要的签名是:

yourFunction : ('a -> Result<'b, 'c>) -> Reader<Result<'a, 'c>> -> Reader<Result<'b, 'c>>

要获得这样的功能,结合Result.bindReader.map

yourFunction f = Reader.map <| Result.bind f