162 karma · joined January 24, 2013
Thanks, raganwald!
Thanks for the information.
One question, though: How do user functions interact in here? If you didn't include `flatten`, but I had my own version of it, would it be straightforward for me to build `process` using my own `flatten`? Do I have to modify some Trine objects, or can I use some simple function references?
Obviously I haven't yet actually dug into the Trine code. Perhaps this weekend.
Ramda is [considering a technique][1] that would significantly reduce call stacks. But there is nothing likely to help with you understand parameter orders of your functions. Many users annotate their functions with something like Haskell signatures.
Thank you for bringing forth another interesting library. I'll be following your progress. Best of luck!
> var isboxed = (function() {"use strict"; return function isboxed() {return this instanceof Number;}}());
> isboxed.call(5);
falseThe best answer to this seems to be simply:
var sum = ls => ls.reduce(add, 0)
ISTM that this is neither as elegant nor as easy to reason about, but it's also not horrible. It really moves away from the easy association that Ramda makes between var currentTotal = reduce(add, 0, nbrs);
and var sum = reduce(add, 0); //=> :: [Number] -> Number
Of course this arrow syntax is ES6 (or transpiler) only, but the library is predicated on that notion. Ramda is a bit of an oddity, still maintaining compatibility with ES3 - ES6. // process1 :: (Item -> Bool) -> [Item] -> [OtherType]
// process2 :: [Item] -> [OtherType]
process1(isOk, items); //=> [otherType1, otherType2, ...]
process2(items); //=> [otherType1, otherType2, ...]
var processR1 = seq(filter, map(toOtherType), flatten);
var processR2 = processR1(isOk);
var processT1 = (isOk, items) => items.filter(isOk).map(toOtherType).flatten()
var processT2 = items => processT1(isOk, items)
That's why I'm wondering if there's some easier way to do this.It was finding that those tools were no longer supporting the way I wanted to work that got me started on Ramda. I'm guessing the same is true for the author of Trine.
This is an interesting approach, but I get caught right at the beginning, where you say "What you'd really want to do is this:
items
.filter(isOk)
.map(toOtherType)
.flatten()
But what I really want to do is build a reusable function: var process = seq(filter(isOk), map(toOtherType), flatten);
So I can at my leisure call process(items);
Or later put `process` in another sequence, or do something like: map(process, groupsOfItems)
And I don't see that Trine helps with that. Am I missing the way to use Trine to build functions, or do I simply have to wrap up a Trine construct in a function that takes a parameter, does its Trine magic, and returns that result?People are going to be told (rightly so) to use `let` instead of `var`. If they do so too mechanically, and their code is structured in certain ways, an expression which could never before throw an exception in Javascript, `typeof x`, now will do so.
This is not the end of the world, by any means. And it doesn't add an exception into unchanged code, but it still is a legitimate concern.
* In a large corporate office with heterogeneous skill-sets among developers, but where almost all had some experience with Javascript.
* Javascript Users Groups
In each case, the idea was to make the case that FP could offer them practical advantages. The goal was definitely not to teach them FP or to suggest the best FP tool.
There are definitely better languages in which to do FP. But if for whatever reasons you're working in Javascript, I would suggest that a functional style could be useful.
That's my primary reason for not testing private functions.
My alternative is simple, and has been stated elsewhere in the thread; if a function rises to the level of complexity of really needing its own tests, then it probably should be exposed as a public function somewhere in my system. Otherwise, I haven't factored the problem properly yet.
The .NET platform of course has F#, which is a dedicated functional language. Some day I'll spend some time learning this one... perhaps.