These are chat archives for ramda/ramda

12th
Sep 2017
Kurt Milam
@kurtmilam
Sep 12 2017 00:18
@buzzdecafe
Apologies. On a mobile and somehow managed to send prematurely 😂
I just learned juxt recently. As you can tell, I like it. I have a tendency to try to fix every problem I come across with the latest nifty tool I've learned.
Simon Friis Vindum
@paldepind
Sep 12 2017 07:00
Hi! I've been working on an immutable list that aims to be very fast and work seamlessly with Ramda. It's still a work in progress but I thought some of you might find it interesting: https://github.com/funkia/list
Syaiful Bahri
@syaiful6
Sep 12 2017 07:06
@paldepind yes, it's interesting. Is it linked list? or something else?
Simon Friis Vindum
@paldepind
Sep 12 2017 07:08
@syaiful6 It's a data structure called relaxed radix balanced-trees. Linked lists are great, but they are very slow at many things. I wanted something that would offer great performance for all operations that JS developers typically do on arrays.
Syaiful Bahri
@syaiful6
Sep 12 2017 07:15
oh, that's the same structure as Elm used right. Maybe the library should not called list, it should Sequence etc.
Simon Friis Vindum
@paldepind
Sep 12 2017 07:17
Yes, it's the same. Do you know if Elm's one can be used from JavaScript? I'd love to add it to my benchmarks.
Do you think sequence is a better name? I kinda prefer list.
Syaiful Bahri
@syaiful6
Sep 12 2017 07:23
I always though list is linked list, so i am probably biased. Never do that kind of benchmarks, Purescript Sequence use Finger Tree based, it's have good performance than Array. But only if you work on large structures, if the structure is small (1000 elements), array doing well.
Simon Friis Vindum
@paldepind
Sep 12 2017 07:25
You're right. List typically means a linked list. I choose the name List because I though it would be the most easily understandable name for JS programmers.
I experimented with finger trees as well. But I got to the same conclusion as Purescript Sequence. The constants are too high. I was able to get RRB-tree to perform better both for small and large lists.
Syaiful Bahri
@syaiful6
Sep 12 2017 07:27
:thumbsup:
James Forbes
@JAForbes
Sep 12 2017 08:13
Looks awesome @paldepind :clap:
Simon Friis Vindum
@paldepind
Sep 12 2017 08:23
@JAForbes Thank you :smiley_cat:
Michael Hurley
@buzzdecafe
Sep 12 2017 12:09
nice @paldepind ! BTW i did a little project with flyd and union-type recently and it was a pure joy to work with those libs
Barry G
@bgits
Sep 12 2017 15:20
How can I make this pointfree? http://dpaste.com/12ZRXJC
Stefano Vozza
@svozza
Sep 12 2017 15:37
you might be able to do something with reduce but that API looks very OOP.
what is BN
Barry G
@bgits
Sep 12 2017 16:06
big number
Stefano Vozza
@svozza
Sep 12 2017 16:16
ah i see
it's a shame because if they were just numbers you could use a combination of reduce and sum
Akshay Iyer
@AkshayIyer12
Sep 12 2017 16:30
let Container = function (x) {
  this.__value = x
}
Container.of = function (x) {
  return new Container(x)
}
var compLaw1 = _.compose(_.map(_.concat(' world')), _.map(_.concat(' cruel')))
var compLaw2 = _.map(_.compose(_.concat(' world'), _.concat(' cruel')))

console.log(compLaw1(Container.of('Goodbye')))
//=> Container(' world cruelGoodbye')

console.log(compLaw2(Container.of('Goodbye')))
//=> Container(' world cruelGoodbye')
Can somebody explain to me how map and concat are working here?
I have used _.map a lot in trying out examples from Mostly Adequate Guide to FP but now I realize that I don't know what map and concat how they are working.
And have come to the realization that I need to read a lot about functors and their use case.
Brad Compton (he/him)
@Bradcomp
Sep 12 2017 16:33
I'll spin up something in the REPL
Julian Coleman
@juliancoleman
Sep 12 2017 16:37

is it possible to get either path?

Kinda like

R.path(
  R.either(["path", "to", "key"], ["path", "to", "otherKey"])
)
Brad Compton (he/him)
@Bradcomp
Sep 12 2017 16:46
@AkshayIyer12 I added some comments as well as the implementation for map here
Can you give me an idea of where you are getting hung up? Is it because the result seems 'backwards'?
Julian Coleman
@juliancoleman
Sep 12 2017 16:47
who?
Brad Compton (he/him)
@Bradcomp
Sep 12 2017 16:47
@juliancoleman I was reference the person above you
@juliancoleman
either(path(["path", "to", "key"]), path(["path", "to", "otherKey"]))
The only issue there is that either will fall through for any falsy values, so a path with 0 or '' will fall through
Akshay Iyer
@AkshayIyer12
Sep 12 2017 16:55
@Bradcomp Thank you. You are a star :+1:
Julian Coleman
@juliancoleman
Sep 12 2017 16:56
That is okay, I don't want those values anyway. Would it be better to use has instead?
btw, thank you for that awesome snippet
Akshay Iyer
@AkshayIyer12
Sep 12 2017 16:57
@Bradcomp I think I'm just getting used to function composition and but it's I think my imperative style which is some sort of hinderance.
Brad Compton (he/him)
@Bradcomp
Sep 12 2017 17:00
@juliancoleman maybe check out:
R.pathSatisfies
Brad Compton (he/him)
@Bradcomp
Sep 12 2017 17:02
@AkshayIyer12 Glad to help :bowtie: :exclamation: Let me know if you need additional clarification
Philipp Wille
@Yord
Sep 12 2017 17:11

@bgits The following implements your function pointfree. I assume the following (mock) implementations for BN and weiToEther:

const BN = function (n) {
  this.n = n;
  this.add = m => this.n += m.n;
  this.toString = () => `BN(${this.n})`
}

const weiToEther = identity

Then, the following pointfree function does what you asked for:

const getPortfolioBalance = pipe(
  chain(prop('balences')),
  reject(propEq('tokenContract', true)),
  pluck('balence'),
  reduceRight(
    uncurryN(2)(
      o(tap, o(invoker(1, 'add'), construct(BN)))
    ),
    construct(BN)(0)
  ),
  toString,
  weiToEther
)

const addresses = [
  { balences: [ { balence: 1 }, { balence: 2 } ] },
  { balences: [ { balence: 3 }, { balence: 1000, tokenContract: true } ] },
  { balences: [ { balence: 4 } ] }
]

getPortfolioBalance(addresses) // "BN(10)"
Simon Friis Vindum
@paldepind
Sep 12 2017 19:42
@buzzdecafe That's great. I'm really happy to hear that :smile: What where you building?
Michael Hurley
@buzzdecafe
Sep 12 2017 20:46
i built a game. for a couple of weeks my son was addicted to it :-)
if you ever had "black box" as a kid, that's what this is
Darren
@dardub
Sep 12 2017 21:28
If I have an Array of objects, and I want to change a value in only one of the objects. It seems easy enough to do that with map, but is there a more appropriate way?
I don't know what lenses are, but my vague understanding from the description seems like it may be related?
Darren
@dardub
Sep 12 2017 21:35
Alright, I think I get lenses now. Seem pretty useful, but I don't have a nested data structure. So doesn't seem necessary.
Brad Compton (he/him)
@Bradcomp
Sep 12 2017 21:40
If you know the index you can use
R.adjust
Brad Compton (he/him)
@Bradcomp
Sep 12 2017 21:41
Otherwise if you need to find the item first you can do `map with
Darren
@dardub
Sep 12 2017 21:41
Hi @Bradcomp , well I can find the index. ;)
Brad Compton (he/him)
@Bradcomp
Sep 12 2017 21:41
R.when
Darren
@dardub
Sep 12 2017 21:41
cool, that's what I've been doing is map and when
Brad Compton (he/him)
@Bradcomp
Sep 12 2017 21:41
:+1:
Darren
@dardub
Sep 12 2017 21:41
thanks!
Kurt Milam
@kurtmilam
Sep 12 2017 21:44
@dardub if it's a large array with many entries, you might want to use R.find to get the index and R.adjust to update the contents, rather than mapping through the entire array. Just something to keep in mind.
Darren
@dardub
Sep 12 2017 21:45
@kurtmilam Ya it's not a large array, and will never get past 20-30 entries. But ya that makes sense for sure.
Kurt Milam
@kurtmilam
Sep 12 2017 21:45
:+1:
Chris Domigan
@cdomigan
Sep 12 2017 22:36
Would I be correct in saying that Ramda and RxJS are complementary libs, and that you wouldn't use one in place of the other?
Brad Compton (he/him)
@Bradcomp
Sep 12 2017 23:33
@cdomigan I would say that's correct, although I am not sure how nicely they play together. Ramda is more of a general utilities library, it doesn't have anything for creating or consuming streams
Ian Hofmann-Hicks
@evilsoft
Sep 12 2017 23:37
@cdomigan I know it is not what you asked, but I have had some amazing "functional synergy" using mostjs for my streaming lib with Ramda. May not be in scope for what your are working on, but my goodness it is an :ok_hand: streaming lib
Michael Hurley
@buzzdecafe
Sep 12 2017 23:38
i would expect ramda to be good with streams, provided the stream lib supports the interface we expect (i.e. essentially, FL)
Ian Hofmann-Hicks
@evilsoft
Sep 12 2017 23:40
they use things like flatMap, but I think there are plans to move to the Rx spec. I think I read some where. I left RX once most came out as it did match.
but you can use it (Ramda that is) for the functions inside of your flatMaps, for most of the api. Just cannot do like point free construction for building a stream flow (I think I used most of the right words there)
One of the many reasons I looked into most (personally)