Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bsgbryan/madul
Mädūl is the fun way to write functional code in TypeScript!
https://github.com/bsgbryan/madul
async bun fun functional functional-programming module module-system typescript typescript-library
Last synced: 3 days ago
JSON representation
Mädūl is the fun way to write functional code in TypeScript!
- Host: GitHub
- URL: https://github.com/bsgbryan/madul
- Owner: bsgbryan
- License: mit
- Created: 2017-05-01T04:06:17.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2024-04-04T22:28:01.000Z (7 months ago)
- Last Synced: 2024-10-07T19:48:03.384Z (about 1 month ago)
- Topics: async, bun, fun, functional, functional-programming, module, module-system, typescript, typescript-library
- Language: TypeScript
- Homepage: https://madul.dev
- Size: 412 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Mädūl
Madul is a simple set of tools that help you craft clean functional code that's straightforward to test - and fun to write & maintain
# Docs
You can find a [Getting Started Guide](https://madul.dev/docs/padawan) and more [here](https://madul.dev) - enjoy! 🤘🏻
## tl;dr
### Madul Definition: `MessageReciever.ts`
```ts
export const dependencies = () => ({
'+/db': ['connectAs', 'getAllMessagesBefore', 'getMessagesFrom']
})export const $init = async ({ connectAs, username }) => await connectAs({ username })
export const getMessagesFrom = async ({
friend,
getAllMessagesBefore,
getMessagesFrom,
sentBefore,
}) => {
const allMessages = await getAllMessagesBefore({ timestamp: sentBefore })
const fromMyFriend = await getMessagesFrom({ friend })return allMessages.filter(m => fromMyFriend.includes(m))
}
```#### In the above code:
1. A madul is just a plain old node module
1. The `db` dependency is loaded asynchronously
1. Dependencies are passed as named parameters to methods
1. The `$init` method is guaranteed to be executed after all dependencies have been loaded, but before the madul is available for use; so you know that the `db` will be properly setup and connected to as `username`### Madul Usage `GetMessagesFromAda.ts`
```ts
import madul from '@bsgbryan/madul'const receiver = await madul('+/MessageReciever', { username: 'KatherineJohnson' })
const oneHour = 1000 * 60 * 60
const sentBefore = Date.now() - oneHourconst messages = await receiver.getMessagesFrom({ friend: 'Ada', sentBefore })
console.log('My messages from Ada!', messages)
```#### In the above code:
1. We pass the `username` used for connecting to the `db` when creating our `madul`
1. We don't call `$init` directly; that's handled for us as part of `madul`
1. We don't pass the `db` dependency to `getMessagesFrom`; that's handled for us