These are chat archives for ramda/ramda

18th
Apr 2017
Martin Broder
@mrtnbroder
Apr 18 2017 00:27
there you go: https://goo.gl/T8lC2N
my working, but unsatisfying version.
Jason Shin
@JasonShin
Apr 18 2017 00:45
hey guys
I want to replace lodash with rambda but there are few functions that's missing in rambda (I think)
for example debounce does not exist in rambda
if you really need debounce in your app, would you use rambda + lodash?
Michael Rosata
@mrosata
Apr 18 2017 00:53
@JasonShin I don't think Ramda has any debounce function to speak of, but I don't think using lodash just for that is the greatest idea either unless your only bringing in that 1 function and not loading the entire lodash lib. Perhaps you could use ramda-fantasy to use Futures, or probably easier still if your just switching over would be to write your own debounce or import a module w/debounce
Jason Shin
@JasonShin
Apr 18 2017 00:55
hmm
right, thanks
Michael Rosata
@mrosata
Apr 18 2017 00:55
:smile_cat:
Brad Compton (he/him)
@Bradcomp
Apr 18 2017 01:54
All of the lodash functions are available as individual modules. I just import that function in the places I need it.
Jason Shin
@JasonShin
Apr 18 2017 04:39
yeah

BTW, do you know why

import _ from 'rambda'

const createArgs = (table, resolver) => {
  console.log('to pairs! : ', _.toPairs(table))
}

export default createArgs

says toPairs is not a function?

Matthew Willhite
@miwillhite
Apr 18 2017 04:45
should be ‘ramda'
Jason Shin
@JasonShin
Apr 18 2017 04:46
lol
Still gives me an error
import R from 'rambda'

const createArgs = (table, resolver) => {
  console.log('to pairs! : ', R.toPairs(table))
}

export default createArgs
@miwillhite
Matthew Willhite
@miwillhite
Apr 18 2017 04:48
the library is ramda not rambda
the latter is a different library
Jason Shin
@JasonShin
Apr 18 2017 04:48
right
yeah, I just figured that out lol
I'm installing ramda now
yarn add ramda
Jason Shin
@JasonShin
Apr 18 2017 05:28
Guys, is it generally very hard to refactor your lodash code to ramda in future?
I'm still learning ramda atm and I just want to continue using lodash until I get my head around it
Martin Broder
@mrtnbroder
Apr 18 2017 08:14
depends on the size of the project, how lodash is used (and which parts of it), etc.
generally saying: it shouldn't be hard.
Maybe you find it easier to use lodash/fp
Martin Broder
@mrtnbroder
Apr 18 2017 08:41
@mrtnbroder :point_up: April 18, 2017 2:27 AM
does someone have a better way of doing this? :D
Mick Dekkers
@mickdekkers
Apr 18 2017 10:52
I'd like to refactor some code that currently uses dependency injection to make use of Readers.
I'm wondering how to compose Readers like I describe here, if it's even possible: https://runkit.com/soullesswaffle/58f5e754d768890011ac0d7c
Aaron Mc Adam
@aaronmcadam
Apr 18 2017 14:57
Hey everyone, is there a more succinct way of expressing this? https://goo.gl/IkGj1F
Michael Rosata
@mrosata
Apr 18 2017 15:01
@aaronmcadam you could do something like this https://goo.gl/MsyZmb but it's really just a refactor, removing assignments. Honestly I think the way you had written it originally may be the best, for readability sake
Aaron Mc Adam
@aaronmcadam
Apr 18 2017 15:02
hah sorry, I left the test case in there for example purposes
I meant the getColour implementation
Michael Rosata
@mrosata
Apr 18 2017 15:02
oh, lol
Denis Stoyanov
@xgrommx
Apr 18 2017 15:02
@aaronmcadam const getColour = useWith(path, [flip(append)(['theme', 'palette']), identity])
Aaron Mc Adam
@aaronmcadam
Apr 18 2017 15:05
Cool, I understand what that does but I wonder if the first version is best to leave
Michael Rosata
@mrosata
Apr 18 2017 15:05
@aaronmcadam probably
Aaron Mc Adam
@aaronmcadam
Apr 18 2017 15:05
thanks @xgrommx!
I think I need a lot more practice to think of these problems more "functionally"
Denis Stoyanov
@xgrommx
Apr 18 2017 15:08
PF isn't a silver bullet, sometime lambda more readable
Aaron Mc Adam
@aaronmcadam
Apr 18 2017 15:08
This is part of a little library I want to write to manipulate theme objects. Here's a suggestion I had before: https://goo.gl/RDuMCR
So I'm thinking I need to read up on lenses and work out how to compose them
Because I essentially just want to build a series of view functions that are partially applied so that clients can just get the leaf nodes/keys
Michael Rosata
@mrosata
Apr 18 2017 16:09
@aaronmcadam whoever suggested that was probably a pretty awesome person :alien: This is a good video on lenses, vimeo.com / 104807358 -- They aren't so complicated once you start using them. I have a utility that comes in handy for turning out lenses. It's probably more than is needed actually but it makes creating lenses simple https://goo.gl/SMY8ou
Aaron Mc Adam
@aaronmcadam
Apr 18 2017 16:12
thanks @mrosata !
So at least I'm right that lenses are the right tool :D
Michael Rosata
@mrosata
Apr 18 2017 16:16
If your going to write point-free and your going to work with nested objects then lenses are the way to go
Robert Mennell
@skatcat31
Apr 18 2017 16:37
How do you guys go about using data multiple times? Do you pass it to more than one chain of functions( Converge, pipes, and such ) or do you store it in a state and have everything take a copy of the state? I'm currently trying to get away from 3 non algebriac functions that mutate state of scope to store some data for later use due to the fact that I have long term non changing data from page load. I was just curious what the status quo is here so that I don't confuse too many people with FP experience that come after me
Matthew Willhite
@miwillhite
Apr 18 2017 16:38
@skatcat31 What is the context/environment? Where does your data live?
Robert Mennell
@skatcat31
Apr 18 2017 16:40
multi distributed systems(100+ distributions) for an aggregation layer. I'm attempting to move away from the couple of outter setters I currently have and more onto properly just preserving the state instead of a global variable with a bound optic that sets, and returns input
Ussually I just leave 1 or 2 impure functions and specific bindings with really specific names, but I was curious how other people do it
often times you'll find mutVARNAME or storeState.variable (depending on reason) if I do an impure, but I'm trying to avoid them. I'm just not finding a good way of storing the serials for later(minutes to hours) polling other than doing a delayed set timeout with the argument being the state and just constantly passing that state along all the time and letting the engine worry about it. That however can lead to some stack problems and until tail call gets better I'd rather avoid the uncaught error in .map.map.map.map.map.map.map.map.map.map.... adnasium
Robert Mennell
@skatcat31
Apr 18 2017 16:48
which the impure fixes somehow and just makes it .map.map.map.toFixed typeerror
Michael Rosata
@mrosata
Apr 18 2017 17:05
@skatcat31 I store in a global typically, but I don't do distributed systems so I can't say that I actually understand your case in point. Maybe using trampolines and thunks at certain points in your compositions could help with the stack issue though
Michael Rosata
@mrosata
Apr 18 2017 17:13
in a nutshell (and probably not even the best nutshell), instead of a function calling itself recursively it returns a function to the original caller (the thunk), and the thunk calls that function. So it breaks recursion basically, the "thunk" just calls the function, unless it's not a function, in which case it assumes that it is the result
Robert Mennell
@skatcat31
Apr 18 2017 17:13
@mrosata right.. yeah had some coffee and remembered using them in my C days
@mrosata I use thunks heavily already XD
Michael Rosata
@mrosata
Apr 18 2017 17:15
:smile:
Robert Mennell
@skatcat31
Apr 18 2017 17:22
@mrosata okay yeah no I'm not remembering trampoline
Robert Mennell
@skatcat31
Apr 18 2017 17:27
@mrosata found a good blog on it though... Maybe unrolling my promise chains and maps into a trampoline might help better...
Michael Rosata
@mrosata
Apr 18 2017 17:28
@skatcat31 I'm going to get back to work, but let me know later if you make any breakthroughs. Maybe your experience will help me as well
Robert Mennell
@skatcat31
Apr 18 2017 17:29
:+1:
00jhou
@00jhou
Apr 18 2017 23:24
Hello! is there a short-hand using ramda for handling this little bugger: obj && obj.key?
or any variation for that matter, obj.key && obj.key.key
Brad Compton (he/him)
@Bradcomp
Apr 18 2017 23:31
Use
R.path
Brad Compton (he/him)
@Bradcomp
Apr 18 2017 23:32
@ram-bot
[
path(['a'], undefined);
path(['a', 'a'], {a: {a: 'a'}})
]
ram-bot
@ram-bot
Apr 18 2017 23:32
Unexpected token ;
Brad Compton (he/him)
@Bradcomp
Apr 18 2017 23:32
@ram-bot
[
path(['a'], undefined),
path(['a', 'a'], {a: {a: 'a'}})
]
ram-bot
@ram-bot
Apr 18 2017 23:32
[ undefined, 'a' ]
00jhou
@00jhou
Apr 18 2017 23:32
oh neat
do you have an example of using lenses as well? examples on the internet are so inconsistent
Brad Compton (he/him)
@Bradcomp
Apr 18 2017 23:47
I guess it depends on what sort of an example you're looking for. I might be able to drum something up later if you let me know what you're trying to do.
00jhou
@00jhou
Apr 18 2017 23:51
taking an array of properties and a couple objects, mapping over the objects to handle those properties?
i'm trying to get a bunch of properties off a bunch of objects
Cody
@Condell
Apr 18 2017 23:52
would anyone be able to point me in the right direction for property based testing functional JS? Specifically testing monads (ramda-fantasy) with JSverify. This probably isnt the best place to ask, but I'm running out of ideas. Thanks!