此模块的文档可以在Module:DataType/doc创建
local D = {}
local C = require("Module:Class")
local F = require("Module:Functional")
local dot = F.dot
local class = C.class
D.Nothing = {
value = {nil},
fmap = function(self, f)
return self
end,
}
D.Just = {
_init = function(self, x)
if x == nil then
return D.Nothing
end
self.value = x
return self
end,
fmap = function(self, f)
self.value = f(self.value)
return self
end,
join = function(self)
return self.value
end
}
D.Just = class(D.Just)
D.IO = {
_init = function(self, f, ...)
local args = {...}
self.performIO = function() return f(args) end
return self
end,
fmap = function(self, f)
self.performIO = dot(f, self.performIO)
return self
end,
}
D.IO = class(D.IO)
return D