Last active
April 28, 2024 08:50
-
-
Save dypsilon/883e878ca1c05a7c355e41fb28a2f3e3 to your computer and use it in GitHub Desktop.
Revisions
-
Tim Navrotskyy revised this gist
Aug 9, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -27,7 +27,7 @@ const encrypt = (i) => crypto.createHash('sha1').update(i).digest('hex'); const encPassword = R.evolve({password: encrypt}) const getInput = () => ({ email: '[email protected]', password: 'secret' }); // this is how you access the db connection inside the reader const save = (user) => { return Reader.ask.map((db) => { db.insert(user); -
Tim Navrotskyy created this gist
Aug 9, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,52 @@ /** * This short program will encrypt the user password * and insert a new record into a mock database. */ const Reader = require('fantasy-readers'); const R = require('ramda'); const crypto = require('crypto'); // our mock database const database = [ { email: '[email protected]', password: 'e0538fd8f022bb3b139d72cf12766cb0e31690ff' }, { email: '[email protected]', password: '42c4fbf6fec201c66b82c97833b08d936d2cd526' } ] // creates a statefull database connection const connectTo = (db) => { return { insert: (doc) => db.push(doc), get: (i) => db[i], delete: (i) => db.splice(i, 1), list: () => db } } // some utility functions const encrypt = (i) => crypto.createHash('sha1').update(i).digest('hex'); const encPassword = R.evolve({password: encrypt}) const getInput = () => ({ email: '[email protected]', password: 'secret' }); // this is how you access the cb connection inside the reader const save = (user) => { return Reader.ask.map((db) => { db.insert(user); return db.list(); }); } // the body of the program const prog = R.pipe( Reader.of, R.map(encPassword), R.chain(save) ); // this is our db connection now const dbCon = connectTo(database); // this is how you pass the db connection in const result = prog(getInput()).run(dbCon); // show the output console.log(result);