Add luarrow.monad module with Identity, Maybe, and Either monads#11
Draft
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>
Copilot
AI
changed the title
[WIP] Future: Add utils for Applicative style function application
Add luarrow.monad module with applicative-style function application
Oct 6, 2025
Owner
|
実装してくれたのは多分Identityモナドだね? 今の実装は |
Co-authored-by: aiya000 <4897842+aiya000@users.noreply.github.com>
Contributor
Author
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:
|
Copilot
AI
changed the title
Add luarrow.monad module with applicative-style function application
Add luarrow.monad module with Identity, Maybe, and Either monads
Oct 6, 2025
341ad26 to
7d3d63d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.