Last active
December 27, 2015 19:49
-
-
Save robotlolita/7379356 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
filters = [ | |
function isEven(a) { return a % 2 === 0 }, | |
function isPositive(a) { return a > 0 } | |
] | |
var items = [-4, -3, -2, -1, 0, 1, 2, 3, 4] | |
// <*> :: [(a -> b)] -> [a] -> [b] | |
function ap(fs){ return function(y) { | |
return fs.map(function(f){ return f(y) })}} | |
// any :: (a -> b) -> [a] -> Bool | |
function any(f){ return function(xs) { | |
return xs.some(f) }} | |
// (f . g) :: (b -> c) -> (a -> b) -> a -> c | |
function compose(f, g) { return function(a) { | |
return f(g(a)) }} | |
// The thing | |
items.filter(compose(any(Boolean), ap(filters))) |
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
filters = [ | |
function is-even(a) => a % 2 === 0 | |
function is-positive(a) => a > 0 | |
] | |
items = [-4, -3, -2, -1, 0, 1, 2, 3, 4] | |
# <*> :: [(a -> b)] -> [a] -> [b] | |
ap = (fs, a) --> fs.map (f) -> f a | |
# any :: (a -> b) -> [a] -> Bool | |
any = (f, xs) --> xs.some f | |
# The thing | |
items.filter (any Boolean . ap filters) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment