我做了一个函数如下:
pen :: (a -> b) -> (b -> a) -> (b -> b) -> a -> a
pen conv rev app = rev . app . conv
Run Code Online (Sandbox Code Playgroud)
其用法如下:
pen read show (\x -> x + 1) "5"
"6"
Run Code Online (Sandbox Code Playgroud)
我对 Haskell 很陌生,我想知道 Haskell 标准库中是否存在这样的函数以及它的名称,因为我在 Hoogle 上找不到它。
我还假设有一些方法可以在没有 (a -> b) -> (b -> a) -> ... 并且只有一个双射函数的情况下实现这一点,但我也不知道该怎么做这个。
干杯!
有没有办法对一组承诺执行异步等待,但只等待第一个完成?
例如:
async function run() {
const ms = Math.floor(Math.random() * 1000);
return new Promise(resolve => setTimeout(resolve, ms));
}
async function test() {
await Promise.first([run(), run(), run(), run(), run()]); // first or similar?
// this line would be reached after the first run() finished execution
// receieve results from first completion
}
Run Code Online (Sandbox Code Playgroud)