Skip to content

Instantly share code, notes, and snippets.

@jgarte
Forked from paf31/UnderscoreFFI.js
Created January 2, 2021 06:24
Show Gist options
  • Save jgarte/b3e1a037e98a0a3e7dc2bb55a5fe8b77 to your computer and use it in GitHub Desktop.
Save jgarte/b3e1a037e98a0a3e7dc2bb55a5fe8b77 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