Add luarrow.monad module with Identity, Maybe, and Either monads#11
Conversation
Co-authored-by: aiya000 <4897842+aiya000@users.noreply.github.com>
Co-authored-by: aiya000 <4897842+aiya000@users.noreply.github.com>
|
実装してくれたのは多分Identityモナドだね? 今の実装は |
Co-authored-by: aiya000 <4897842+aiya000@users.noreply.github.com>
Done! I've refactored the monad implementation:
All three are exported from the main Each monad includes appropriate methods ( Commit: Refactor monad module into Identity, Maybe, and Either monads Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
341ad26 to
7d3d63d
Compare
|
メモ: |
Overview
This PR implements the
luarrow.monadmodule, adding support for monadic programming with three core monads: Identity, Maybe, and Either. The module provides Haskell-inspired monadic operations with Lua's operator overloading for elegant composition.What's New
Three Monad Implementations
1. Identity Monad
The simplest monad that wraps values in a computational context, enabling applicative-style function composition:
Note:
pureis available as an alias foridentityfor backward compatibility.2. Maybe Monad
Represents optional values with
just(value)for values andnothing()for absence:3. Either Monad
Represents computations that may fail with
right(value)for success andleft(error)for failures:How It Works
Each monad provides:
fmap(via*operator): Map functions over wrapped valuesbind(via%operator): Chain monadic computationsor_else: Extract value with a default fallbackImplementation Details
New Files
src/luarrow/monad/identity.lua: Identity monad implementationsrc/luarrow/monad/maybe.lua: Maybe monad implementationsrc/luarrow/monad/either.lua: Either monad implementationsrc/luarrow/monad.lua: Main module exporting all three monadsspec/luarrow/monad/identity_spec.lua: Identity monad testsspec/luarrow/monad/maybe_spec.lua: Maybe monad tests (9 tests)spec/luarrow/monad/either_spec.lua: Either monad tests (11 tests)Updated Files
src/luarrow.lua: Exports all monad functions (identity/pure,just,nothing,right,left)doc/api.md: Complete API documentation for all three monads with examplesREADME.md: Added monad overview and examplesdoc/examples.md: Added practical monad usage examplesspec/luarrow/monad_spec.lua: Original tests maintained for backward compatibilitysrc/luarrow/fun.lua,src/luarrow/arrow.lua, andscripts/benchmark.luaDesign Philosophy
The implementation follows Haskell's monad conventions while maintaining luarrow's patterns:
*for fmap,%for bind)purestill works as an alias foridentityTesting
All tests pass (20+ tests total):
The test suite covers:
pureimplementationDocumentation
Complete documentation has been added following the existing style:
doc/api.mdwith detailed monad explanations and type signaturesdoc/examples.mdshowing practical use casesREADME.mdCloses
Closes #7
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.