原文 那么monad 到底是什么呢? 它是一种设计模式。只要你有一堆函数,当它们接受一个参数而返回另一个值,就可以用以下两个函数把那些函数组合在一起。
- bind 函数将其他函数变换成 输入参数与返回值 类型相同的类型, 使它们可以组合起来。
- unit 函数将一个值包装成组合函数可以接受的模式
原文 那么monad 到底是什么呢? 它是一种设计模式。只要你有一堆函数,当它们接受一个参数而返回另一个值,就可以用以下两个函数把那些函数组合在一起。
#!/usr/bin/lua5.1 | |
--- Async/Await for Lua 5.1 | |
-- This script implements async/await functions for Lua, allowing tasks to | |
-- be queued and scheduled independently. | |
-- | |
-- This is just an example and has a bunch of issues, isn't tested, isn't | |
-- even actually used anywhere; I basically just got bored and had one of | |
-- those "what if?" type ideas 6 hours ago. | |
local co_create = coroutine.create |