These are chat archives for ramda/ramda

13th
Sep 2016
Robin Wenglewski
@rweng
Sep 13 2016 06:52
@kwijibo I changed my mind after watching https://www.youtube.com/watch?v=E8I19uA-wGY&feature=youtu.be and follow your suggestion of curried functions now :)
Keith Alexander
@kwijibo
Sep 13 2016 08:13
@rweng Scott Wlaschin's stuff is very good - was there something in particular that changed your mind?
Keith Alexander
@kwijibo
Sep 13 2016 08:21
(IMO there doesn't seem to be one clear best way to do dependencies; each has trade-offs, it depends on how the function/method/whatever will be used)
Robin Wenglewski
@rweng
Sep 13 2016 08:56
@kwijibo well, not really, just after the talk and the analogy with rail roads, and your input of having the configuration/dependencies first parameter which I can destruct in js, it seems cleaner to me to export single, curried functions than to export only one "factory" function with which I might generate functions I do not even want to use in a particular use-case. I guess your right, both ways are valid, but for now I am going with this approach. And thanks, I'll look into more of Scott's material! There is lots to learn when you come from a oop-focused background :)
Robin Wenglewski
@rweng
Sep 13 2016 10:11
I am trying to refactor this lens factory (https://gist.github.com/rweng/f2300f029078c1f920ef3023bbc6eae4) so that it does not point to a static index, but applies the whereFn only when view/set/over is called. I guess I need to use lens directly instead of lensPath, but I am failing to get the setter together. Any experienced fp guy here to give me a hint? ;)
Robin Wenglewski
@rweng
Sep 13 2016 10:31
ok, I've found a way around it, but still far away from being satisfied: https://gist.github.com/rweng/f2300f029078c1f920ef3023bbc6eae4
I hope ramda contains a function to replace the index === -1 check, and one to replace the external dependency to updeep :)
Nick Kenny
@uberteck
Sep 13 2016 11:37
I hope this is the right place to ask this. I have an array of values and a function which needs to do something with each of those values, which is an asynchronous action. The function returns a data.task. In other code I've been using a lot of traverse(Task.of, func, array).fork(), but in this case - I need to guarantee each task has finished before the next is executed. The side effect of the function is operating on the same thing and the order the mutations occur is important. Does Ramda have a function that does effectively the equivalent of bluebird's Promise.mapSeries but with tasks? I had a look through the "what function should I use" in the wiki but am none the wiser. I'm guessing I should be using chain somehow but I'm new to functional programming and can't figure out how to wire it all together. Any hints which Ramda functions I should be looking at?
Keith Alexander
@kwijibo
Sep 13 2016 12:01

@uberteck
I guess it comes down to something like this?

reduce(
(listTask, k)=> 
     getVal(k).chain((val)=>
          listTask.map(list => [...list, val]))
, Task.of([]))

but maybe there's a higher-level abstraction

Syaiful Bahri
@syaiful6
Sep 13 2016 12:13
@ubertect if i understand your question, you can use Rambda sequence function.
function mapM(of, f, ms) {
  return R.sequence(of, ms.map(f))
}

usage:

mapM(Task.of, func, listofTask)
Syaiful Bahri
@syaiful6
Sep 13 2016 12:22
ah, @uberteck Rambda traverse and sequence use ap under the hood, that why your task executed in parallel, you might use different version of sequence using chain instead.. https://github.com/folktale/control.monads/blob/master/lib/basic.js
Keith Alexander
@kwijibo
Sep 13 2016 12:24
sequence is a misleading name in this case :)
Denis Stoyanov
@xgrommx
Sep 13 2016 12:29
@syaiful6 mapM === traverse
Syaiful Bahri
@syaiful6
Sep 13 2016 12:30
@xgrommx yes, i know. i am not remember if rambda have that functions. :)
Denis Stoyanov
@xgrommx
Sep 13 2016 12:30
I like this in haskell
Avoid String.
Use fmap instead of map.
Use Foldable and Traversable instead of the Control.Monad, and Data.List versions of traversals.
Avoid partial functions like head and read or use their total variants.
Avoid exceptions, use ExceptT or Either instead.
Avoid boolean blind functions.
Craig Dallimore
@craigdallimore
Sep 13 2016 15:20
@xgrommx where is this from?
Denis Stoyanov
@xgrommx
Sep 13 2016 15:21
@craigdallimore this resource really interesting http://dev.stephendiehl.com/hask/#what-to-avoid
Craig Dallimore
@craigdallimore
Sep 13 2016 15:23

Much ink has been spilled waxing lyrical about the supposed mystique of monads. Instead, I suggest a path to enlightenment:
Don't read the monad tutorials.
No really, don't read the monad tutorials.
Learn about Haskell types

Haha love it

Alastair Hole
@afhole
Sep 13 2016 15:59
Does pluck only work on lists/arrays or could it work on any functor, e.g. data.validation pluck('pluckMe', Success( {pluckMe: 123} ))?
LeonineKing1199
@LeonineKing1199
Sep 13 2016 16:06
It maps prop
So if your functor can take prop and use it, then yeah
Alastair Hole
@afhole
Sep 13 2016 16:09
Ah ok so it only plucks one level deep?
Damn
Brad Compton (he/him)
@Bradcomp
Sep 13 2016 16:10
Looks like it works on Maybe :-D
Alastair Hole
@afhole
Sep 13 2016 16:12
Was hoping pluck would handle multiple levels of props like RxJS' pluck
Still pretty cool that it works on any functor though :D
LeonineKing1199
@LeonineKing1199
Sep 13 2016 16:14
If you look at the source code, it's definitely a list-centric function
Brad Compton (he/him)
@Bradcomp
Sep 13 2016 16:14
You mean, like pluck('pluckMe', Success( {pluckMe: 123} )) === 123?
Alastair Hole
@afhole
Sep 13 2016 16:16
Like pluck(['one', 'two'], Success( {one:{two: 123}} )) === 123
i.e. path-like behaviour. I'll just have to map path or make a new function to do the same
Not sure how standard the definition of pluck is, RxJS has spoilt me with its path type behaviour
Still though very cool that in this case the list-centric-ness is satisfied by anything that implements map
LeonineKing1199
@LeonineKing1199
Sep 13 2016 16:20
Oh yeah, why not just map `path?
Denis Stoyanov
@xgrommx
Sep 13 2016 16:21
map(path(['one', 'two']), Success( {one:{two: 123}} )) @afhole
Alastair Hole
@afhole
Sep 13 2016 16:35
How would I compose map and path into a new function that took a path array and and a functor?
Brad Compton (he/him)
@Bradcomp
Sep 13 2016 16:36
const mapPath = curry((p, functor) => map(path(p), functor))?
Or, if you wanted to get all tacit on it
const mapPath = useWith(map, [path, identity])
Alastair Hole
@afhole
Sep 13 2016 16:37
Oooh yes that's the one :)
I managed to remove mention of the functor but couldn't see how to get rid of the path array
Not used useWith before, that's awesome, thank you :)
Nick Kenny
@uberteck
Sep 13 2016 17:28
@kwijibo, @syaiful6, thank you both. useful link too.
Vladimir Kapustin
@kapooostin
Sep 13 2016 19:45
A question about converge. Here is an example in REPL http://goo.gl/ynsCDA. I do not understand why flip(path) behaves differently when used as a branch function in converge.
Nick Luparev
@SuperManEver
Sep 13 2016 19:54
Hello. I have kinda general question. According to documentation whole Ramba API divided into groups, like Function, Logic, List, and so on ... What is Relation for ? Relational programming I guess ?
Paul
@pauloliver
Sep 13 2016 19:56
Looks to me like they all deal with some form of value comparison
Nick Luparev
@SuperManEver
Sep 13 2016 19:57
@pauloliver Personally, I try to figure is it possible to do Prolog-like things using API provided in Relation section
LeonineKing1199
@LeonineKing1199
Sep 13 2016 19:58
That sounds like "all I've used is a hammer so everything is a nail"
LeonineKing1199
@LeonineKing1199
Sep 13 2016 20:04
But to pauloliver's point, the Relation algorithms will typically deal with how data relate to each other
You have the comparison functions and some set-based functions as well
Nick Luparev
@SuperManEver
Sep 13 2016 20:06
I see, essentially you mean I need to have some sort of backtracking algorithm in order to find how different entities relate to each other
LeonineKing1199
@LeonineKing1199
Sep 13 2016 20:07
Backtracking?
It might help us all if you defined what you were hoping to accomplish.
For example, > operator can be used to find the relation between 1 and 2
There's no "backtracking" in there as far as I can tell
Nick Luparev
@SuperManEver
Sep 13 2016 20:09
I start to see intent of this part of Ramda API :-)
name Relation confused me at first, I started to think that I can do Prolog-like things using it.
actually I need to do some research on this subject. I think it's possible to do kinda like Relational programming and the necessary API should be small and relatively simple. There is think called miniKanren which essential does this
LeonineKing1199
@LeonineKing1199
Sep 13 2016 20:13
I've never touched logic programming so I've no idea lol
I try to program with as little logic as possible :P
Nick Luparev
@SuperManEver
Sep 13 2016 20:13
:smile:
LeonineKing1199
@LeonineKing1199
Sep 13 2016 20:18
I've never really done any functional programming either. I try to avoid functions. Everything I've ever wrote is in just one file :laughing:
Brad Compton (he/him)
@Bradcomp
Sep 13 2016 20:25
@SuperManEver I ran across this recently. Might be similar to what you are looking for?
Michael Hurley
@buzzdecafe
Sep 13 2016 22:20
FWIW, ramda-logic is a minikanren impl.
just a toy for me; one of my pet interests