These are chat archives for ramda/ramda

9th
Dec 2018
Rakesh Pai
@rakeshpai
Dec 09 2018 13:55
OT, but did anyone give today's Advent of Code a shot with ramda? I've had to give up on Ramda for solving today's puzzle.
Resorted to a linked-list implementation I wrote in plain JS, with mutability and all. How does one implement an immutable linked-list?
(Sorry if I gave it away - took me quite some time before I realised it was a linked list. Woops!)
Scott Sauyet
@CrossEye
Dec 09 2018 15:08
I haven't done any of them since the first half of Friday's. Would like to try them today.
Asad Saeeduddin
@masaeedu
Dec 09 2018 15:46
@rakeshpai It seems like an immutable linked list would be easier than a mutable one (at least for a singly linked list)
Rakesh Pai
@rakeshpai
Dec 09 2018 15:47
Agreed, for singly linked list. But a doubly-linked list would be impossible?
Asad Saeeduddin
@masaeedu
Dec 09 2018 15:47
no, that should be possible as well
Rakesh Pai
@rakeshpai
Dec 09 2018 15:49
With immutability? Won't the changes propagate across the entire chain, making it impossible?
Asad Saeeduddin
@masaeedu
Dec 09 2018 15:53
yes, if you change a node, you'll have to transitively change all the links
Rakesh Pai
@rakeshpai
Dec 09 2018 15:55
I'm not familiar with other pure-functional programming languages, but I wonder how one could implement a doubly-linked-list in them.
Asad Saeeduddin
@masaeedu
Dec 09 2018 16:06
i haven't implemented it before, but i imagine in haskell you'd do something like this:
data DLinkedList a = Nil | Cons { left :: DLinkedList a, current :: a, right :: DLinkedList a } deriving Show
then you can build lists like so:
mylist = x where
  x = Cons Nil 1 y
  y = Cons x 2 z
  z = Cons y 3 Nil
you do have to transitively update everything when you change anything though, so it doesn't really give you any of the performance characteristics of a normal linked list
there's alternative functional structures that have equivalent performance characteristics, e.g. fast lookup for last element or fast append, so if you formulate the search in terms of that you might find some good results
Rakesh Pai
@rakeshpai
Dec 09 2018 16:17
That's interesting. What are these functional structures that allow for these? What do I google for?
Asad Saeeduddin
@masaeedu
Dec 09 2018 16:19
are you looking for fast append?
if i look for "haskell constant time append" the first link i find is this: https://stackoverflow.com/questions/5188286/idiomatic-efficient-haskell-append
which is based on finger trees
you could also pull the DList trick, which works for any monoid
Rakesh Pai
@rakeshpai
Dec 09 2018 16:22
That should give me something to explore. Thanks for the pointers!
Asad Saeeduddin
@masaeedu
Dec 09 2018 16:34
i found this talk as well that i'm watching now: https://www.youtube.com/watch?v=-HZ4bo_USvE
the title is a bit of a lie, it's the same principle; he looks for what performance characteristics we want and then implements the appropriate functional programming data structure for getting those performance characteristics (instead of a doubly linked list)
Rakesh Pai
@rakeshpai
Dec 09 2018 16:36
Will look. Thanks.
Alexander Lichter
@manniL
Dec 09 2018 20:17
@rakeshpai did use an array solution and just waited ages :see_no_evil:
(for the 2nd part)