These are chat archives for ramda/ramda

10th
Oct 2016
Keith Alexander
@kwijibo
Oct 10 2016 06:41
https://www.surveymonkey.com/r/fp_ladder <- I don't get this survey
If there is a logical order of dependency in FP concepts, why do you need a survey to find out what it is? If there isn't, why does it matter what a survey of opinion says the order should be?
Markus Pfundstein
@MarkusPfundstein
Oct 10 2016 06:54
I think it makes sense to get idea about how to teach people FP. You certainly don’t start with Profunctors but probably with pure functions, higher-order functions, composition and alike
a lot of people I work with still see functions as something different then objects and don’t grasph that you can do with them whatever you want… They also don’t quite get the benefits of immutable ds and pure functions… mostly because no one taught them … but still this are the basics of FP..
Markus Pfundstein
@MarkusPfundstein
Oct 10 2016 06:59
more stupid is that some answers are XOR :P
Keith Alexander
@kwijibo
Oct 10 2016 09:02
Sure, but there is a logical dependency between pure functions and composition
Scott Christopher
@scott-christopher
Oct 10 2016 09:47

@jigargosar

in my example I am storing the id of currently selected note, so I need to fetch it when rendering the note body/title editor
also I need to traverse the graph, with previous and next elements, when arrow keys are pressed.

I just realised that this is pretty much the exact description of a Zipper type, which is a data structure that acts like a cursor and is used to walk around another data type like your tree, keeping track of the "current" node and allowing immutable updates, etc.

I don't have much time free right now, but I can get an example together later if you're interested.
Jigar Gosar
@jigargosar
Oct 10 2016 09:55
@scott-christopher totally interested. Take your time.
meanwhile I will dig up on Zipper type.
thanks
Keith Alexander
@kwijibo
Oct 10 2016 10:28
@scott-christopher that sounds really interesting
Jigar Gosar
@jigargosar
Oct 10 2016 11:22
found this library for zipper https://github.com/tommikaikkonen/zippa
but it doesn't allow to save a cursor position. :(
if visit method could have returned a zipper pointing at node, where visit was stopped, it would have been more useful.
http://aaronstacy.com/t-js/ is also a nice library intended only for traversal.
perhaps I could implement my own zipper ;)
Jigar Gosar
@jigargosar
Oct 10 2016 12:20

Function composition pattern: is there some concept of passing context to composed functions?

a(b(c(1))) === compose(a,b,c)(1)
a(b(c(1, ctx), ctx), ctx) === ???

one solution I could think of was

const fnWithCtx = map(partialRight(_.__, ctx) , a,b,c)
apply(compose, fnWithCtx)

I have a feeling that, this has a better solution already. @scott-christopher what say you?

p.s: ignore my wonky partialRight syntax, I presume you get the idea.
applicatives? monads? some lifting?
Syaiful Bahri
@syaiful6
Oct 10 2016 12:23
context for this?
i mean context for javascript this?
Jigar Gosar
@jigargosar
Oct 10 2016 12:33
this has nothing to do with this :D
actually applicationState is more apt.
state
Syaiful Bahri
@syaiful6
Oct 10 2016 12:34
i see, maybe you need S combinator
Jigar Gosar
@jigargosar
Oct 10 2016 12:35
okies, will check it out. thanks.
Syaiful Bahri
@syaiful6
Oct 10 2016 12:36
maybe look like this S = f => g => x => f(x)(g(x))
Jigar Gosar
@jigargosar
Oct 10 2016 12:37
found an old gist by https://gist.github.com/buzzdecafe/6261503 @buzzdecafe ;)
@jigargosar That's the general idea ^
Jigar Gosar
@jigargosar
Oct 10 2016 12:39
@scott-christopher thanks. Looks very similar to https://github.com/tommikaikkonen/zippa
thanks for taking so much pain to help me. I will go through it in detail.
Scott Christopher
@scott-christopher
Oct 10 2016 12:43
You're welcome. I'll have to take a closer look at that zippa library, but it looks good at a quick glance.
Jigar Gosar
@jigargosar
Oct 10 2016 12:47
i am using visit function from it to find prev and next nodes, of a node matching the id predicate.
we will have to write our own dfs vist function for our Tree right?
Jigar Gosar
@jigargosar
Oct 10 2016 12:53
@scott-christopher also in our Tree Cursor implementation, once we call toforest we loose the cursor position of the node that was update, and further traversal is not possible, right? then do we have to create a new tree and repeat the steps to reach the node that was last updated?
Scott Christopher
@scott-christopher
Oct 10 2016 12:54
you can always just keep the cursor around
that will save your current position (assuming nothing mutates the tree instance)
are the IDs used for any other purpose than to keep track of the current node?
Jigar Gosar
@jigargosar
Oct 10 2016 12:57
@scott-christopher for now they are just used to keep track of current node, but once any node gets modified, we will have to retrace the steps to reach the old cursor position right?
@xgrommx that is pretty dense, thanks. Will have to study in depth.
Scott Christopher
@scott-christopher
Oct 10 2016 12:59
Nope, you can just keep the cursor that is returned when calling
cursor.modifyContent()
I should clarify that you don't need to call cursor.toTree() or cursor.toForest() to get the data out.
Jigar Gosar
@jigargosar
Oct 10 2016 13:01
@scott-christopher aah! that is super cool. Thanks, this is exactly what I needed.
now I just need to serialize/deserilize cursor. from local storage, upon app reload.
@scott-christopher then how do I render the modified tree?
Scott Christopher
@scott-christopher
Oct 10 2016 13:05
I guess that depends on how you plan on rendering it.
Jigar Gosar
@jigargosar
Oct 10 2016 13:09
I am using react to render app state.
Scott Christopher
@scott-christopher
Oct 10 2016 13:10
so you need to translate the tree of notes into a tree of react components?
Jigar Gosar
@jigargosar
Oct 10 2016 13:10
yes.
and ensure that selected component gets extra attribute.
If I store isSelected as an attribute in the tree model itself, then it should work.
Scott Christopher
@scott-christopher
Oct 10 2016 13:11
the selected component being the one that is currently focussed on by the cursor?
Jigar Gosar
@jigargosar
Oct 10 2016 13:11
yes.
currently I am maintaing tree + idOfSelected node
as app state {notes:[...], selectedNoteID:10}
Scott Christopher
@scott-christopher
Oct 10 2016 13:14
I suspect your state could simply become the cursor, where you'll then need to recursively map the nodes around the current item.
Jigar Gosar
@jigargosar
Oct 10 2016 13:15
is there a way to have two cursors, one pointing at root so that I can traverse it for rendering, another pointing at selectedNode, so that I can update it.
both sharing the same backend tree state?
otherwise I will have to extract out the updated forest for rendering purposes only. And use Tree as single source of truth for entire app state.
Markus Pfundstein
@MarkusPfundstein
Oct 10 2016 13:17
you always have a cursor at the root as long as you have a reference right?
Jigar Gosar
@jigargosar
Oct 10 2016 13:18
reference to old state? or newly modified state which is only held by one cursor.
I need access to new modified state as well as currently selected node. for rendering/navigation and making updates.
@MarkusPfundstein so once a cursor is used to go to root, we lose reference to the selected node.

@scott-christopher

I suspect your state could simply become the cursor, where you'll then need to recursively map the nodes around the current item.
"recursively map the nodes around the current item." didn't get last bit.

Jigar Gosar
@jigargosar
Oct 10 2016 13:25
did you mean, use cursor as state, and call toForest for rendering purposes?
Scott Christopher
@scott-christopher
Oct 10 2016 13:26
from the focus of the cursor, you have access to all the parent, sibling and child nodes, so I suspect there should be a way to transform that structure such that it ends up something like
renderParents(
  cursor.parents,
  renderNodes(cursor.before),
  renderFocused(cursor.content(), cursor.children()),
  renderNodes(cursor.after)
)
Jigar Gosar
@jigargosar
Oct 10 2016 13:27
humm!!
Scott Christopher
@scott-christopher
Oct 10 2016 13:28
... or if it is easier to transform it from the tree, then you could just call toForest in render()
Jigar Gosar
@jigargosar
Oct 10 2016 13:28
calling toForest seems much simpler than this. as you said, storing the cursor returned by modifiedContent should give me uptodate state :)
@scott-christopher yup, thanks a lot. This has solved a big hurdle for me. Going off to build the next killer app ;)
Scott Christopher
@scott-christopher
Oct 10 2016 13:30
:D best of luck with it all
Jigar Gosar
@jigargosar
Oct 10 2016 13:31
thanks :)