These are chat archives for ramda/ramda

26th
Oct 2017
Philipp Wille
@Yord
Oct 26 2017 05:17
With a bowtie halo? ;)
Ivan Vodich
@Ivan456
Oct 26 2017 07:38

Hello guys,
i wanna apply the same function to each argument in this way:
R.useWith(Math.pow, R.dec)(3, 5);

But works only this:
R.useWith(Math.pow, [R.dec, R.dec])(3, 4);

ladershowitz
@ladz
Oct 26 2017 07:39

Hey guys! I'm looking for a way to do this snippet

const toggleCartVisibilityLens = lensProp("toggleCartVisibility");

const assocLinkProps = pipe(
  assocPath(["linkProps", "style"], { color: "#924d63" }),
  assocPath(["linkProps", "className"], "nav-item-link"),
  props =>
    assocPath(
      ["linkProps", "onClick"],
      view(toggleCartVisibilityLens, props),
      props
    )
);

point-free (line 4-9). Any ideas?

Andrzej Lichnerowicz
@unjello
Oct 26 2017 08:55
@Bradcomp ok. got it finally :) eh... there's much more to JS then I thought it was... still fighting with its flexibility compared to C++ or even C#/Java :)
Jin
@Justin-ZS
Oct 26 2017 09:29
@ladz converage(assocPath(["linkProps", "onClick"]), [view(toggleCartVisibilityLens), identity]), mabe it work
````
ladershowitz
@ladz
Oct 26 2017 09:34
@Justin-ZS It works! I did not know about converge, very useful. Thanks!
arian‮
@arian-swydo
Oct 26 2017 12:27
@ladz or if you don't care about the feelings of your coworkers you could try:
ap( flip(assocPath(["linkProps", "onClick"])) )
  ( view(lensProp(toggleCartVisibilityLens)) )
passive agressive innovation
Joey Figaro
@joeyfigaro
Oct 26 2017 12:58
Hey all. I’m gearing up to deal with inserting words into an array of empty strings [‘ ‘, ‘ ‘, ‘ ‘, ‘ ‘, ...] at a specific index, but it needs to account for the length of the inserted word, insert each character separately starting at the index specified, and end at whatever index the word’s last character happens to land. Basically making an array of empty strings, inserting split words starting at a given index, and ensuring that it replaces the empty strings that exist in the range.
Anyone have any thoughts/terminology/patterns that might apply or be of interest?
insert ‘testing@test.com’ at index 2 -> [‘ ‘, ‘ ‘, ’t’, ‘e’, ’s’, ’t’, ‘i’, ’n’, ‘g’, ‘@‘, ’t’, ‘e’, ’s’, ’t’, ‘.’, ‘c’, ‘o’, ‘m’, ‘ ‘, ‘ ‘, ‘ ']
MateuszTrN
@MateuszTrN
Oct 26 2017 14:57
@Ivan456 I'm not sure what are you trying to achieve therefore I don't understand what your problem is, cause you wrote that you've found the solution
arian‮
@arian-swydo
Oct 26 2017 15:15
@joeyfigaro , I'm gonna get banned for this, but the way you describe it, I would just pray no one will code review it and use splice: https://goo.gl/vtSpXm
Brad Compton (he/him)
@Bradcomp
Oct 26 2017 15:15
:laughing:
That looks pretty good to me
arian‮
@arian-swydo
Oct 26 2017 15:19
thanks, I'm a blast at parties
Ivan Vodich
@Ivan456
Oct 26 2017 15:26
@MateuszTrN i tried to achieve next behavior to apply R.dec to every argument: R.useWith(Math.pow, R.dec)(3, 5);
thank you.
Joey Figaro
@joeyfigaro
Oct 26 2017 16:13
@arian-swydo insertIntoEmptyVoidThatIsMyLife rofl
Joey Figaro
@joeyfigaro
Oct 26 2017 16:21
Thanks @arian-swydo—we’re working on making IRS electric submissions a thing. They require the submitted file to be ascii, and each piece of data from a document has to be at a given index. Python script I stumbled upon: http://bazaar.launchpad.net/~tim-alwaysreformed/python-irs-fire-api/trunk/view/head:/fire.py#L40
Sean Lindo
@seanlindo
Oct 26 2017 16:56
Hi all. The output of this code snippet is a bootstrap color. Nothing fancy
const scoreColor = R.compose(getScoreColor, R.view(idLens), GetPropertyScoreDescription)(score)
What I would really like the output to be is an object comprised of the score and the score color. That would allow me to pass the output into a final function, which spits out a React component. That said, I'm not sure how that would work
Robert Mennell
@skatcat31
Oct 26 2017 17:10
good news is you're halfway there. converge should help
after that a getScore function should be one of the converging functions, and function of const singleZip = (a,b) -> zipObj([[a],[b]] as the convergence point. At that point you get your object of {score:color}. Unless I missunderstood and you want a different looking object
Sean Lindo
@seanlindo
Oct 26 2017 17:16
{ score: 36, color: "#F5F5F5" } something like that. I'm looking into converge now
Robert Mennell
@skatcat31
Oct 26 2017 17:16
maybe the converging function is more like (score, color) -> zipObj( [ [ 'score', 'color' ], [ score, color ] ] )
Sean Lindo
@seanlindo
Oct 26 2017 17:17
yes!
onboarding new developers is going to be a blast.
Robert Mennell
@skatcat31
Oct 26 2017 17:18
If they're worth their weight in Javascript or programming in general it'll be easy XD
It's the "developers"(read: scripter/coder) that will be harder to onboard...
Sean Lindo
@seanlindo
Oct 26 2017 17:20
once you get the concepts, the rest is easier. just a matter of finding the right approach to a problem
some of my resistance to hiring from something like a code bootcamp relates to math. we use it at work a good bit-- linear algebra, calculus, etc.
after seeing some algebraic data types pop up while exploring FP, it made me wonder
Robert Mennell
@skatcat31
Oct 26 2017 17:22
"A program is nothing mroe than solving a word problem with a computer"
If htey aren't good at solving word problems...
Sean Lindo
@seanlindo
Oct 26 2017 17:22
true
Joey Figaro
@joeyfigaro
Oct 26 2017 17:23
Does anyone have any bookmarked/favorite examples of sequence or converge in use?
Robert Mennell
@skatcat31
Oct 26 2017 17:29
have you checked the cookbook and the what function do I use pages of the wiki?
There's a really good example of converge in spread
Joey Figaro
@joeyfigaro
Oct 26 2017 17:33
I had, but on checking again I ran across apply, which seems to be what I want. Trying to get around arity requirements of pipe for a function that takes 3 args.
Hmm. Looks like remaining functions need to be unary, though.
(b -> b -> c) -> (a -> b) -> a -> a -> c
Connor Brathwaite
@connorbrathwaite
Oct 26 2017 18:00

hi everyone, had a quick question: trying to call a fn only passing it arguments conditionally, otherwise it should simply be invoked with empty args.

const invalidValueMessage = R.ifElse(
  R.lt(R.__, 1),
  R.always("should not be negative"),
  R.always(undefined)
)

validator: (rule, value, cb) => R.useWith(cb, [invalidValueMessage])(value)

surely there is a more appropriate approach :worried:

Jethro Larson
@jethrolarson
Oct 26 2017 18:08
If it's a pattern you like you can always make a helper
const foo = (pred, msg) => x => pred(x) ? msg : undefined
const invalidValueMessage = foo(R.lt(R.__, 1), 'should not be negative')
I'm doing something similar in my project using Either to separate success from failure
Connor Brathwaite
@connorbrathwaite
Oct 26 2017 18:13
interesting, but i was aiming to avoid the ifElse and simply use when, however value is piped into cb
Billy Le
@lebilly
Oct 26 2017 18:16
Hello everyone~!
Jethro Larson
@jethrolarson
Oct 26 2017 18:17
there's a big difference between identity and always(undefined)
Hi @lebilly
FP doesn't usually like undefined
when is ~
const when = pred => f => ifElse(pred, f, identity)
Connor Brathwaite
@connorbrathwaite
Oct 26 2017 18:22
so there it is, makes much more sense now
Jethro Larson
@jethrolarson
Oct 26 2017 18:23
so you can make a special version of that with always(undefined) instead
Billy Le
@lebilly
Oct 26 2017 18:23
I'm very new to Ramda, and was wondering if I can get some help on filtering out false values on a nested object.
Jethro Larson
@jethrolarson
Oct 26 2017 18:24
specifically false or all falsy?
Connor Brathwaite
@connorbrathwaite
Oct 26 2017 18:24
or a single predicate cond ?
Kevin Wallace
@kedashoe
Oct 26 2017 18:25
@jethrolarson I believe on has been discussed a few times but not sure if a PR has ever come up
Jethro Larson
@jethrolarson
Oct 26 2017 18:25
@kedashoe Ah, yeah. I keep looking for it. Kind of completes the grammar with useWith and converge
Billy Le
@lebilly
Oct 26 2017 18:26
Specifically false. I'm validating an object that is passed in. So far, I've used R.evolve() to do what I want it to do and now I'm trying to figure out how I can use map/filter to remove all the false values from a nested object like such:
{
  goalCategoryId: true,
  need: {
    id: true,
    name: false
  },
  item: {
    id: false,
    name: true
  }
}

// I want it to look like this
{
  goalCategoryId: true,
  need: {
    id: true
  }
}
Brad Compton (he/him)
@Bradcomp
Oct 26 2017 18:27
Try something like this: https://goo.gl/AhkDA7
Billy Le
@lebilly
Oct 26 2017 18:28
Nice, I think I can work with this. Thanks @Bradcomp !
Kevin Wallace
@kedashoe
Oct 26 2017 18:29
interesting i never use those two functions so might be missing out on a neat usage in js, but on of course very nice in haskell
Brad Compton (he/him)
@Bradcomp
Oct 26 2017 18:30
on exists in sanctuary, it's easy to define in terms of useWith or just as a stand alone function. I like it, but it reads a lot cleaner as an infix operator than as a prefix function
Jethro Larson
@jethrolarson
Oct 26 2017 18:31
@lebilly You'll probably thank yourself if you make the objects homogenous
Billy Le
@lebilly
Oct 26 2017 18:31
I don't know what you mean by homogenous but i'll look it up.
Jethro Larson
@jethrolarson
Oct 26 2017 18:32
I just mean keep the shapes of the objects you're iterating over consistent
Billy Le
@lebilly
Oct 26 2017 18:32
Ah, okay. Thank you for the tip!
Jethro Larson
@jethrolarson
Oct 26 2017 18:33
{
  goalCategoryId: true,
  stuff: {
    need: {
      id: true,
      name: false
    },
    item: {
      id: false,
      name: true
    }
  }
}
with that structure the code gets simpler since you know that "name" aways exists for the stuff
Billy Le
@lebilly
Oct 26 2017 18:36
That's a great idea. Now I can see what you mean by iterating over that.
Jethro Larson
@jethrolarson
Oct 26 2017 18:36
Actually, I think I get what you're doing now. This is an arbitrarily nested tree where all leaves are bool
That true?
Billy Le
@lebilly
Oct 26 2017 18:37
Pretty much. I just want to be able to remove all the false values from this object.
Jethro Larson
@jethrolarson
Oct 26 2017 18:38
If that's true then you'll probably want to do this recurrsively
Billy Le
@lebilly
Oct 26 2017 18:38
But I think the example that @Bradcomp gave me is more than enough for me to work with.
Jethro Larson
@jethrolarson
Oct 26 2017 18:39
His code assumes that the key names matter
or rather that you'd want different behavior based on key name
Billy Le
@lebilly
Oct 26 2017 18:40
Yes, it does. Lol I just realized that if I validated the object with just true values, I won't be able to update the database with the real values. Lol I'm still learning :P
Jethro Larson
@jethrolarson
Oct 26 2017 18:40
:)
Billy Le
@lebilly
Oct 26 2017 18:41
But thank you very much for spending time with me.
Charles F. Munat
@chasm
Oct 26 2017 19:14
Hello. I'm building a small web app to teach FP and am wondering if the lovely Ramda REPL can be used within it for learning purposes. Does anyone know if this is possible/permitted? If so, are there examples I might look at for the best way to do it? I'm working with React and the latest JS. TIA.
Scott Sauyet
@CrossEye
Oct 26 2017 19:27
I can't imagine anyone would object. You might want to raise an issue on the https://github.com/ramda/repl project just to be sure.
I have no experience trying to use it elsewhere, though.
Charles F. Munat
@chasm
Oct 26 2017 20:05
Thanks, @CrossEye. Will do.