Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jimmy-collazos/advice-function
Implementation of Advice pattern for functional programing
https://github.com/jimmy-collazos/advice-function
Last synced: about 2 months ago
JSON representation
Implementation of Advice pattern for functional programing
- Host: GitHub
- URL: https://github.com/jimmy-collazos/advice-function
- Owner: jimmy-collazos
- License: mit
- Created: 2018-05-07T21:12:32.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-04-09T08:25:48.000Z (almost 3 years ago)
- Last Synced: 2024-09-24T09:11:43.700Z (4 months ago)
- Language: JavaScript
- Size: 18.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Advice Function
This is a basic implementation of [Advice](https://en.wikipedia.org/wiki/Advice_(programming)) pattern for functional programing.
## Before and After
Both functions called with the same arguments of the main functions. These functions don`t change the value of arguments or result value of main function.### Example
```javascript
import advice from 'advice-function'// hello world
const greeting = (pattern) => (name) => (pattern.replace('{name}', name))
const hello = advice(greeting('Hello {name}'))
.before((name) => console.log('show wellcome message to', name))
.after((name) => console.log(name, 'is greeted'))hello('world')
```## Arround
This decorator is the best of decorators, because we can use to multiple porpuse (replace arguments, call to another methods after and before to call main function, ....)If You don´t set any function to Arround list, main function is called.
### Example
```javascript
import advice from 'advice-function'// hello world
const greeting = (pattern) => (name) => (pattern.replace('{name}', name))
const hello = advice(greeting('Hello {name}'))
.arround((mainFn) => (name) => {
console.log('show wellcome message to', name)
mainFn(name.toUpperCase())
console.log(name, 'is greeted')
})hello('world')
```## License
currency-format is licensed under the [MIT License](LICENSE).