Kekka
Result Monad adaptation for easy usage in JavaScript
Install / Use
/learn @Apemb/KekkaREADME
Kekka
A set of monad objects to simplify and clarify your business logic:
- Result
- Optional
The first object is the Result Object inspired by Rust Result Monad. The second is the java inspired Optional.
GOAL
Managing unsuccessful but not erroneous return value
Never felt that something was missing in Javascript way of managing errors ?
A middle ground between returning undefined for business reasons and throwing Errors for business reasons.
getUser(userId) // returns undefined if no user found
.then((user) => {
if(!user) {
// do stuff knowing user was not found
}
})
Or throwing errors for business reasons ?
getUser(userId) // returns undefined if no user found
.catch((error) => {
if(error instanceof NoUserFoundError) {
// do stuff knowing user was not found
}
})
Ever heard about Railway Programming ? or the Rust Result Monad ?
Wanting something like that in Javascript ? I did ! Enter the Result class.
Defeating defensive programming
Tired of writing endless guard clauses like
if(!userName) {
return
}
or
if(user && user.name) {
// do something
}
Maybe want more elegant and explicit way to signal optional values in your business logic ?
Look out for the Optional class
Changelog
- v4.0: Add Optional Object
- v3.0: Fix broken import from different modules in mono-repo
- v2.0: Transcription to Typescript
- Typescript Types
- Suppression of enableResultPromiseHelpers function
- Removal of support for non-native promises
Documentation
Result Object Documentation
Optional Object Documentation
There is a chai plugin available to make sweeter assertions: chai-kekka.
Related Skills
node-connect
339.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
83.9kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
339.3kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
83.9kCommit, push, and open a PR
