by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jan 31 2019 22:17
    CrossEye commented #2779
  • Jan 31 2019 21:04
    ArturAralin commented #2779
  • Jan 31 2019 20:08
    CrossEye commented #2779
  • Jan 31 2019 18:56
    buzzdecafe commented #2631
  • Jan 31 2019 18:09
    ArturAralin commented #2779
  • Jan 31 2019 16:18
    CrossEye commented #2779
  • Jan 31 2019 16:10
    CrossEye commented #2631
  • Jan 31 2019 16:06
    CrossEye commented #2777
  • Jan 31 2019 14:44
    ArturAralin opened #2779
  • Jan 31 2019 07:39
    inferusvv commented #2631
  • Jan 31 2019 03:07
    sespinozj commented #2771
  • Jan 31 2019 02:33
    machad0 commented #2771
  • Jan 31 2019 02:26
    JeffreyChan commented #2777
  • Jan 30 2019 14:30
    CrossEye closed #2777
  • Jan 30 2019 12:13
    vanyadymousky updated the wiki
  • Jan 30 2019 01:42
    JeffreyChan commented #2777
  • Jan 29 2019 21:06
    vanyadymousky updated the wiki
  • Jan 29 2019 16:28
    CrossEye commented #2777
  • Jan 29 2019 15:50
    mbostock commented #2772
  • Jan 29 2019 15:48
    CrossEye commented #2772
Karsten Pruehss
@kpruehss
wow ok. I'm going to need a minute to wrap my head around this.
Ben Briggs
@ben-eb
Sure, no worries :)
Karsten Pruehss
@kpruehss
ok i think I slowly get whats happening here. the fns object holds the various types of predicates i may want to use, in this case eq for propEq and say, cf for a custom filter. I then push an array of strings laying out the predicate type, the prop and the value, and push that onto the filters array when a filter is selected. the filterFn then composes the allPass with the map to generate a single array of predicates to pass to filter. Is that roughly whats happening?
Ben Briggs
@ben-eb
Precisely! :)
Karsten Pruehss
@kpruehss
cool!
Ben Briggs
@ben-eb
And like I mentioned you could even drop this fn map and pass the functions around, e.g [[R.propEq, 'foo', 'bar']]
Karsten Pruehss
@kpruehss
this will also make it easy to add more filter predicate types later on by just tacking them onto fns. very cool!
Ben Briggs
@ben-eb
Depends on how you're generating this list really :)
Cool, hope it works out! :D
Karsten Pruehss
@kpruehss
thank you!! Now to the refactor :D
I think I prefer the idea of using the map tbh :). Feels more like I have a single point for filter definitions. Without the map, I'd have to pass fat-arrow functions in the array for custom filters, or am I misunderstanding something?
Ben Briggs
@ben-eb
Functions are first class citizens in JS, so you can do that. Either inline or using a reference, e.g:
const customFn = x => x;

[[customFn, 'a', 'b']] // reference
[[x => x, 'a', 'b']] // inline
Karsten Pruehss
@kpruehss
oh wait nevermind. As you pointed out, the generator would handle that. Still feels easier to follow for me using the map
Ben Briggs
@ben-eb
Yep. If it were me I'd probably prefer the map too
Karsten Pruehss
@kpruehss
seriously, thank you! This really helped me shift my thinking a bit
Ben Briggs
@ben-eb
@kpruehss You're very welcome :)
Marc Fogleman
@MFogleman

I have an applySpec and Promise problem

I am calling a database, getting back the document. I need to do a bunch of transforms based off the data gotten back, so I'm using an applySpec. It works great. But one of the fields in my spec needs to make a GET request to another server, and get the response. applySpec does not wait on promises. I figure there are 4 possible solutions

  1. There is a combination of wrapping this in async/awaits and R.then, to make this wait on the result, and I just dont know what it is
  2. This is a terrible anti pattern that I shouldnt be using at all
  3. Someone wrote a utility to solve this exactly (I found promise-apply-spec, but I think it may be a bit heavy for what I want)
  4. I'm going to need to hand roll either my own version of applySpec, or wrappers to handle this

If anyone has more experience in this or similar issues, feedback and guidance is appreciated

Ben Briggs
@ben-eb
@MFogleman You could also look into using a lazy data structure e.g. https://github.com/fluture-js/Fluture - not sure how well it would work with applySpec though to be honest
coffeefedora
@coffeefedora
i have a common paradigm, wondering if this has a functional term and maybe has a ramda function for it. I frequently do something like this: myObject[key] = myObject[key] || [];
so basically, get an existing array there or start one. i also do an object version of it
it's not exactly a long thing to type, but i was curious
kinda looks like a mergeRight maybe? myObject[key] = R.mergeRight(myObject[key], []);
but i'd love to just do: Init(myObject[key], []); and then its done
coffeefedora
@coffeefedora
although i'm dumb, it'd be Init(myObject, key, []);
Ben Briggs
@ben-eb
@coffeefedora I'd probably look at doing this when you want to extract the value out, then you can do propOr. e.g:
const results = R.propOr([], key, myObject);
In FP land we don't want to mutate our original object, so I think an Init function that has that interface would not be a good practice
coffeefedora
@coffeefedora
yeah that kind of makes sense. i set it the way i do to make looping easier when i am adding to the array
maybe i can re-organize my code and make it a little bit differently
Ben Briggs
@ben-eb
Yup :smile:
Hyunseok Oh
@algoshipda
  R.compose(
    R.fromPairs,
    R.zip(['x', 'y', 'z']),
    R.props(['a', 'b', 'c']),
  )
any equivalent function?
Twizzes
@Twizzes
@algoshipda That looks good to me, it seems to me there wouldn't be any much easier ways to specify a mapping like that. Are you looking for something that exhibits the same behavior in a different way?
Hyunseok Oh
@algoshipda
@Twizzes Can't with just one ramda function?
Ben Briggs
@ben-eb
@algoshipda 4 -> 3 with R.o(R.zipObj(['x', 'y', 'z']), R.props(['a', 'b', 'c']))
Oscar Bolmsten
@oscar-b
Is there a "preferred" style for pipe/compose when auto formatting? Any maintainer who would care to chime in? prettier/prettier#6921
Twizzes
@Twizzes
sorry if sanctuary is verbotten
Charles Hughes
@chughes87
anyone know a nice way to update all the keys in a given object? I need to prefix them all with a static string.. Object.entries and then R.zip comes to mind but I wish there was a cleaner way...
Brad Compton (he/him)
@Bradcomp
Something like this?
Charles Hughes
@chughes87
oh hell yall are already talking about this sorry for not reading :laughing:
Brad Compton (he/him)
@Bradcomp
Oh no prob! The wiki isn't well publicized
I try to bring it up whenever I can :smile:
Charles Hughes
@chughes87
@Twizzes do you strongly prefer Sanctuary to Ramda? I'm curious about it
Also I just wanna do a shout out. I've been using Ramda for a few months now and it is just glorious. Thanks to the developers/maintainers so much :pray:
Twizzes
@Twizzes
@chughes87 the sanctuary docs do a much better job at explaining the differences than I ever could:
For a direct function to function comparison, see: https://github.com/sanctuary-js/sanctuary/wiki/Ramda-to-Sanctuary
As you can see, sanctuary is more focused, and embraces further some of the concepts of functional programming, whereas ramda has a lot more utility functions and relaxes some of the constraints traditional FP enforces, making ramda somewhat more user friendly to folks from imperitive backgrounds
Twizzes
@Twizzes
Ramda is an easier sell to established teams using OOP, sanctuary is more for getting as close to FP in JavaScript as possible and a great way to learn FP for js devs
Patrick Laplante
@patbonecrusher
Hello all, really dumb question. How would you handle something like a socket in a composition chain. For instance, how would I do something like this but using functional composition.
Url = “localhost:8080”
connection = open_connection(url)
result = Send_data(connection, data)
raw_response = Get_response(connection)
response = parse(response)