Skip to content

Commit

Permalink
Merge pull request #165 from slntRohit/recoursion-example
Browse files Browse the repository at this point in the history
Added recursion example
  • Loading branch information
joelnet committed Oct 11, 2018
2 parents c85cd99 + eb7b4cc commit f242d41
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ MojiScript's design is derived from Functional Programming concepts such as Curr
* [Conditionals](examples/conditionals)
* [map/filter/reduce](examples/map-filter-reduce)
* [FizzBuzz](examples/fizz-buzz)
* [Recursion](examples/recursion)
- [API](API.md)
- [Style Guide](#style-guide)
- [Complementary Libraries](#complementary-libraries)
Expand Down
54 changes: 54 additions & 0 deletions examples/recursion/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# MojiScript Recursion

MojiScript Recursion example.

## Install

```bash
# clone repository
git clone https://github.com/joelnet/MojiScript.git

# enter directory
cd MojiScript/examples/recursion

# install dependencies
npm ci
```

## Run

```bash
npm start
```

You should see the output

```
1
2
3
4
5
6
...
```
Will keep printing numbers every 1 second.

## Code

```javascript
import log from 'mojiscript/console/log'
import pipe from 'mojiscript/core/pipe'
import run from 'mojiscript/core/run'
import wait from 'mojiscript/threading/sleep'

const state = 1

const main = pipe ([
log,
wait (1000),
x => main (x + 1)
])

run ({ state, main })
```
14 changes: 14 additions & 0 deletions examples/recursion/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import log from 'mojiscript/console/log'
import pipe from 'mojiscript/core/pipe'
import run from 'mojiscript/core/run'
import wait from 'mojiscript/threading/sleep'

const state = 1

const main = pipe ([
log,
wait (1000),
x => main (x + 1)
])

run ({ state, main })
13 changes: 13 additions & 0 deletions examples/recursion/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "recursion",
"version": "1.0.0",
"author": "Joel Thoms",
"license": "MIT",
"main": "index.mjs",
"scripts": {
"start": "node --experimental-modules --no-warnings index.mjs"
},
"dependencies": {
"mojiscript": "file:../.."
}
}

0 comments on commit f242d41

Please sign in to comment.