Skip to content

Instantly share code, notes, and snippets.

@benzen
Forked from fxg42/exercices.js
Last active November 5, 2015 19:10
Show Gist options
  • Save benzen/9bc097e478ea8e368d2c to your computer and use it in GitHub Desktop.
Save benzen/9bc097e478ea8e368d2c to your computer and use it in GitHub Desktop.
Exercices
// # Exercice 1:
// Étant données les deux fonctions suivantes:
// f :: a -> [b]
var f = (a) => [ a * a ];
// g :: a -> [b]
var g = (a) => [ a + 10 ];
// Écris l'implémentation de la fonction `compose` définie ainsi:
// compose :: (a->[b]) -> (a->[b]) -> (a->[b])
// p.e.
// var h = compose(f, g);
// h //=> (a) => [ (a+10) * (a+10) ]
// h(2) //=> [ 144 ]
var compose = (k1, k2) => {
return k1(k2(a));
};
// # Exercice 2:
// Étant données `f`, `g` et `compose`, écris la fonction `bind` définie ainsi:
// bind :: [a] -> (a -> [b]) -> [b]
// p.e.
// bind([1,2,3], compose(f,g)) //=> [121, 144, 169]
var bind = (list, k) => {
return _.flatten(list.map(k));// peut mieux faire, p.ex sans lodash
};
// # Exercice 3:
// Vérifie que ceci est vrai:
//
// bind(bind([1,2,3], g), f) === [121, 144, 169]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment