Skip to content

Instantly share code, notes, and snippets.

@greathmaster
Last active February 16, 2020 03:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greathmaster/68373ac95a612023affc0dad47a30318 to your computer and use it in GitHub Desktop.
Save greathmaster/68373ac95a612023affc0dad47a30318 to your computer and use it in GitHub Desktop.
Unlocking a secret using curry principles.
//Example 1:
Function.prototype.secretCurry = function() {
let secret = "password"
let that = this;
return function inner(guess) {
if(guess == secret) {
that();
}
return inner;
}
}
function log() {
console.log("You unlocked the secret!")
}
let f = log.secretCurry();
f("test123")("abc")("password")
//Example 2:
function curryingExample(str) {
let curryStr = ""
curryStr += str;
return function curryReturn(str2) {
if(str2 === undefined) {
return curryStr;
}
else {
curryStr += str2;
return curryReturn
}
}
}
console.log(curryingExample("My ")("name ")("is ")("Snoopy!")())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment