These are chat archives for ramda/ramda

Apr 2017
James Forbes
Apr 08 2017 00:15

@polytypic apologies, when I said "illegal" I meant it in the most clinical sense. I'm not saying illegal lenses are bad, I'm just saying "hey if you cross this line, you're now in partial territory", I think partial lenses are cool and useful, and I use them.

Just like I use partial functions on occasion when they are useful for performance.

I use the word illegal because we use the word "law", maybe that's a bad idea because it has negative connotations.

And when I said you don't need to use another library to create partial lenses, I didn't mean you shouldn't.

I just didn't want anyone to think that ramda couldn't absorb nulls on its own. I even went so far as to recommend partial.lenses for fully exploring that domain.

I also wouldn't presume to know more about lenses, or FP than you or anyone here. It's very likely I don't know, as I've only really started using them this year. But I find conversations that appeal to authority are brittle, and if we challenge and discuss topics on their merit, we'll have more fruitful interesting discussions (and we do!).

(Great example of this is the proposal to add fantasy land support to Rx, there's a lot of posturing about expertise, which is a total waste of time, no-one was questioning that expertise, and the assumption that they were says a lot.)

On a side node, and this is directed to the FP community at large: I think the "infamous ladder" is hugely problematic, knowledge isn't hierarchical, it's a graph. And just because someone knows a lot about topic A, doesn't mean they couldn't gain insights by interacting with someone who's experience is in column B. Appealing to authority is needless, because having experience should provide you with the tools to make your case on its own merit with greater elegance than a novice. We should respect experts, but should also seek to understand why, and not simply assume they are right due to their authority.

Some of the best discussions I've witnessed are between 2 people from different fields resolving their own contexts and perspectives respectfully. If one of those 2 is a novice, that's still a separate context that yields valuable information. The expert is forced to focus their knowledge into razor sharp analogies or more precise descriptions for the benefit of the beginner, in turn it benefits everyone.

Brian Beckman comes to mind "functional programming is programming with functions", or Rich Hickey carving out the void between "simple" and "easy". This framing benefits novices, but its also valuable in the deepest vein of expertise.

Notice the justification is not "functional programming is programming with functions because I'm Brian Beckman so you better believe it!", or "Programming with Monads is analogous to railway track design because I'm Scott Wlashcin". They all justify their position from first principles, despite their expertise, but we benefit from the clarity their expertise provides.

Philipp Wille
Apr 08 2017 20:53
I have been playing around with lenses and was wondering why there is a lensProp, but no lensPropOr? I would find a lensPropOr insanely useful for the same reasons as propOr. As it was simple enough to come up with my own implementation of lensPropOr, maybe the reason is it would add unnecessary additional complexity? Does anybody know wether this topic has come up before?
James Forbes
Apr 08 2017 22:01

You can create it via or => key => lens(propOr(or, key), assoc(key))


var lensPropOr = (or, key) => lens(propOr(or, key), assoc(key))

var a = lensPropOr([], 'a')

view(a, {}) //=> []
view(a, { a: [1,2,3] }) //=> [1,2,3]

over(a, append(1), {}) //=> 1
@Yord oh sorry, just saw you said you had your own :smile:
@Yord Maybe create an issue to add it. @polytypic has made some great points here that partiality is extremely useful. So it may be worthwhile to have a few more primitives in ramda.
Vesa Karvonen
Apr 08 2017 22:56

Well, I think there might be a sort of misunderstanding about partial lenses. It is not that partial lenses would just throw out laws and reasoning. Quite the contrary.

"Lenses" in Ramda are not (total) lenses, which is something that has been recognised by several people already and even before partial lenses library was created. Crucially, Ramda does not currently properly specify the partial behaviour of lenses. In that sense partial lenses arguably makes things significantly more clearly specified, lawful and reasonable.

The goal in partial lenses has been to make something that works well in the context of a "dynamically typed" language like JavaScript rather than simply copy concepts from existing statically typed libraries. The sort of partiality concept that you have in partial lenses would simply not work as nicely in statically typed language with a mainly nominal type system. It might be possible to get a similar partiality concept to work in a language that has a fully structural type system.

Dually, there are aspects that can't be so nicely translated from statically typed languages to JavaScript. For example, in some of the statically typed libraries you can use to to lift an ordinary function to compose it with optics to obtain a Getter. The nice thing is that the type system also then reflects the properties of the composition. In partial lenses you can also compose optics and ordinary functions and the result is a "read-only" optic such that writing through the optic has no effect. What can be static semantics in a statically typed language becomes dynamic semantics in a dynamically typed language.