Skip to content

Instantly share code, notes, and snippets.

@naomik

naomik/point-free.js

Last active Aug 29, 2015
Embed
What would you like to do?
help me go point free!
var sub = y => x => x - y;
var idx = i => xs => xs[i]
var len = idx("length");
var head = idx(0);
// this works, but can we go point free?
var last = xs => idx(sub(1)(len(xs)))(xs);
// this feels slightly closer, but i'm still trying to eliminate `xs`
var last = (xs) => compose([idx, sub(1), len])(xs)(xs)
// ultimately i need something that represents
// var last = (xs) => xs[xs.length - 1]
// hmm HOW ABOUT THIS?
var slice = i => xs => xs.slice(i);
var last = compose([head, slice(-1)]);
last([1,2,3,4,5]); //=> 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.