This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Future = require('fluture') | |
const Either = require('fantasy-eithers') | |
const r = require('ramda') | |
const lefts = r.reduce( | |
(memo, either) => { | |
let extract | |
either.bimap(x => extract = x, r.identity) | |
return extract ? r.append(extract, memo) : memo | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express') | |
var app = express() | |
var port = process.env.PORT || 8080 | |
var router = express.Router() | |
router.get('/', function(req, res) { | |
res.json({ message: 'Welcome to the api!' }) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Future = require('fluture') | |
const got = require('got') | |
const futureFetch = (url, options) => { | |
return new Future((reject, resolve) => { | |
got(url, options).then(resolve).catch(reject) | |
}) | |
} | |
futureFetch( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const r = require('ramda') | |
const lefts = r.reduce( | |
(memo, either) => { | |
let extract | |
either.bimap(x => extract = x, r.identity) | |
return extract ? r.append(extract, memo) : memo | |
}, | |
[] | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Future = require('fluture') | |
var fs = require('fs') | |
var readFile = filename => { | |
return new Future((reject, resolve) => | |
fs.readFile(filename, 'utf-8', (err, data) => | |
err ? reject(err) : resolve(data) | |
) | |
) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {StateT} from "fantasy-states" | |
import {Future} from "ramda-fantasy" | |
import {compose, composeK, merge, always} from "ramda" | |
// Make a new monad from Future and StateT (State Transformer) | |
const StateF = StateT(Future) | |
const {get, modify} = StateF | |
const babies = [ | |
{id: 2, name: "Alice", sex: "F"}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "state-test", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "Mark", | |
"license": "ISC", |