Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/iokasimov/observable
Make your actions observable and listen events from them, algebraically.
https://github.com/iokasimov/observable
continuation observer
Last synced: 2 months ago
JSON representation
Make your actions observable and listen events from them, algebraically.
- Host: GitHub
- URL: https://github.com/iokasimov/observable
- Owner: iokasimov
- License: bsd-3-clause
- Created: 2018-06-13T13:39:53.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-12-10T14:20:28.000Z (about 6 years ago)
- Last Synced: 2023-09-20T09:34:27.076Z (over 1 year ago)
- Topics: continuation, observer
- Language: Haskell
- Homepage: http://hackage.haskell.org/package/observable
- Size: 26.4 KB
- Stars: 14
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Make your actions to be observable and listen events from them, algebraically.
Let's imagine simple example: we want to listen to STDIN. We have `getLine` function that can capture a list of ASCII-symbols - all we need is to make this action to be observable.
```haskell
obs :: Monad f => f a -> Observable f a r
```
Good, now we want to subscribe on events and set up callback, if we want to listen events forever, we need `subscribe` function:```haskell
subscribe :: Applicative f => Observable f a r -> (a -> f r) -> f r
```First, we make action to be observable, then set up callback and at the end, subscribe on events:
```haskell
subscribe (obs getLine) handler
```Our handler will count amount of characters in strings and send this into STDOUT:
```haskell
handler = print . (<>) "Length of string was: " . show . length
```Let's try it out:
```haskell
> hello, my dear friend!
> "Length of string was: 22"
```