Created
August 7, 2019 15:02
-
-
Save iampeterbanjo/b8a8bb5f904209aad09becf5a9b70226 to your computer and use it in GitHub Desktop.
This file contains 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
(function() { | |
console.log('Hello from the snippet'); | |
const user = { | |
name: 'Cassie Cage' | |
}; | |
const exampleTarget = { | |
firstname: 'Cassie', | |
surname: 'Cage', | |
}; | |
const mapping = f => reducing => (result, input) => | |
reducing(result, f(input)); | |
const filtering = predicate => reducing => (result, input) => | |
predicate(input) ? reducing(result, input) : result; | |
const chain = (xs, x) => xs.concat(x); | |
const result = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | |
.reduce(mapping(x => x + 1)(chain), []) | |
.reduce(filtering(x => x % 2 === 0)(chain), []); | |
// [2, 4, 6, 8, 10] | |
console.log(result); | |
const inspect = x => { | |
console.log(x); | |
return x; | |
} | |
const doNothing = x => x; | |
const parseName = x => { | |
const { name } = x; | |
const [firstname, surname] = name.split(' '); | |
const result = { firstname, surname }; | |
return result; | |
}; | |
[user] | |
.reduce(mapping(inspect)(chain), []) | |
.reduce(mapping(parseName)(chain), []) | |
.reduce(mapping(doNothing)(chain), []) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment