Skip to content

Instantly share code, notes, and snippets.

@paf31
Last active January 2, 2021 06:24
Show Gist options
  • Save paf31/3aedd6c3e3ac5c8a78e7 to your computer and use it in GitHub Desktop.
Save paf31/3aedd6c3e3ac5c8a78e7 to your computer and use it in GitHub Desktop.
Minimal UnderscoreJS Binding for PureScript
"use strict";
// module UnderscoreFFI
exports.map = function(f) {
return function (arr) {
return require('underscore').map(arr, f);
};
};
exports.reduce = function(f) {
return function (memo) {
return function (arr) {
return require('underscore').reduce(arr, function(memo, a) {
return f(memo)(a);
}, memo);
};
};
};
function reduceRight(f) {
return function (memo) {
return function (arr) {
return require('underscore').reduceRight(arr, function(memo, a) {
return f(memo)(a);
}, memo);
};
};
};
exports.sortBy = function(f) {
return function (arr) {
return require('underscore').sortBy(arr, f);
};
};
exports.shuffle = function(arr) {
return require('underscore').shuffle(arr);
};
exports.uniq = function (arr) {
return require('underscore').uniq(arr);
};
module UnderscoreFFI where
foreign import map :: forall a b. (a -> b) -> Array a -> Array b
foreign import reduce :: forall a b. (a -> b -> a) -> a -> Array b -> a
foreign import reduceRight :: forall a b. (a -> b -> a) -> a -> Array b -> a
foreign import sortBy :: forall a. (a -> Number) -> Array a -> Array a
foreign import shuffle :: forall a. Array a -> Array a
foreign import uniq :: forall a. Array a -> Array a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment