These are chat archives for ramda/ramda

22nd
May 2017
Rick Medina
@rickmed
May 22 2017 00:06
applicative (ap)
@JasonShin
Brad Compton (he/him)
@Bradcomp
May 22 2017 00:06

R.useWith would work, but I would look into applicative to accomplish what you need.

Then takeTwoValuesAndCalc could just take the types inside the Futures directly, and return you back a Future of the result

Same time :stuck_out_tongue:
Jason Shin
@JasonShin
May 22 2017 00:13
cool
Denis Stoyanov
@xgrommx
May 22 2017 08:03

@mrosata

permutations' = sortByM' (\_ _ -> [False, True])
subsequences' = filterM' (const [False, True])
inits' = takeWhileM' (const [False, True])
tails' = dropWhileM' (const [False, True])

I wrote sortByM', filterM', takeWhileM', dropWhileM' via recursion schemes (para, cata, cataM, paraM)

Jason Shin
@JasonShin
May 22 2017 12:18
hey guys, what do you think about renaming
forEachObjectIndexed
to
forOwn
forOwn name used in Lodash for exactly same function (except for the method being curried)
Jordy Vialoux
@JordyVialoux
May 22 2017 13:09
Hey guys, how can I update state using ramda like this: case actions.CAROUSEL_NEXT: return assocPath([ 'carousel', 'selectedIndex' + 1 ], state);
will I need to use something like inc or dec?
Denis Stoyanov
@xgrommx
May 22 2017 13:11
evolve
Jordy Vialoux
@JordyVialoux
May 22 2017 13:11
@xgrommx sorry?
Tom Harding
@i-am-tom
May 22 2017 13:12
I think Denis means ramdajs.com/docs/#evolve !
hahaha
Tom Harding
@i-am-tom
May 22 2017 13:12
^_^
Joey Figaro
@joeyfigaro
May 22 2017 13:12
That guy's got an example of using evolve in a reducer
Jordy Vialoux
@JordyVialoux
May 22 2017 13:16
so like this then? return inc([ 'carousel', 'selectedIndex' ], state);
Joey Figaro
@joeyfigaro
May 22 2017 13:20
@JordyVialoux evolve takes an object that specifies a transformation function for each key. In this case, we’re specifying that the value of the completed property should be transformed by the not function.
If you're looking to increment, you should be able to specify inc inside your evolve for whatever key you're looking to increment.
Galileo Sanchez
@galileopy
May 22 2017 13:21
return evolve( {carousel: {selectedIndex: inc}}, state)
Joey Figaro
@joeyfigaro
May 22 2017 13:21
:clap:
Galileo Sanchez
@galileopy
May 22 2017 13:22
something like that should work
evolve an applySpec are very useful to get handle state
also const evolveApply = (evolver, spec, state) => merge (evolve(evolver, state), applySpec(spec, state))
Jordy Vialoux
@JordyVialoux
May 22 2017 13:23
@joeyfigaro thank you for this mate - works a treat
I did the same for decrement as well
Jonah
@jonahx
May 22 2017 13:30

question for @xgrommx or others versed in the theory of FP. from the wikipedia page on backus’s function level programming, discussing the difference between what most of us call functional programming today (what backus called “applicative programming”), and backus’s more restrictive function level programming, they write:

This restriction means that functions in FP (jonah’s note: FP = function-level programming here) are a module (generated by the built-in functions) over the algebra of functional forms, and are thus algebraically tractable. For instance, the general question of equality of two functions is equivalent to the halting problem, and is undecidable, but equality of two functions in FP is just equality in the algebra, and thus (Backus imagines) easier.

The implication of the sly phrase “Backus imagines” is never clarified. Is he now known to be mistaken? Is he now known to be correct? Is the question still an open one?

Denis Stoyanov
@xgrommx
May 22 2017 13:31
lazy people, don't want to read docs, they just want that we should provide them solution :(
James Forbes
@JAForbes
May 22 2017 13:31
@xgrommx I think its more that your one word answer had a double meaning
Galileo Sanchez
@galileopy
May 22 2017 13:31
lazy people are the majority?
James Forbes
@JAForbes
May 22 2017 13:31
that was also hilarious
Galileo Sanchez
@galileopy
May 22 2017 13:32
that's why democracy sucks? lol
I prefer to think that as a lack of familiarity with the tool, and the learned helplessness effect
James Forbes
@JAForbes
May 22 2017 13:33
Also ramda's doc's aren't perfect, and therefore that claim is a stretch
Denis Stoyanov
@xgrommx
May 22 2017 13:33
@JAForbes okay, sorry
James Forbes
@JAForbes
May 22 2017 13:34
:+1:
Galileo Sanchez
@galileopy
May 22 2017 13:34
@JAForbes they're pretty good though, there are some rough edges in what transducers are :sweat_smile:
Denis Stoyanov
@xgrommx
May 22 2017 13:34
today my BD :smile:
James Forbes
@JAForbes
May 22 2017 13:34
happy birthday!
Galileo Sanchez
@galileopy
May 22 2017 13:34
congrats @xgrommx, you're a positive force !!!
Denis Stoyanov
@xgrommx
May 22 2017 13:34
thx :smile:
Michael Rosata
@mrosata
May 22 2017 13:35
@xgrommx I just bookmarked some resources on recursion schemes. I'm able to read some recursion schemes, like a data type for a tree perhaps. I have taken a "swing and a miss" at |.| catamorphisms before as well and come up short. I threw the definitions of permutations', subsequences', inits' and tails' into a file. Maybe I'll be able to come up with takeWhileM', dropWhileM' and sortByM' hopefully when I have some spare time.
happy b-day
James Forbes
@JAForbes
May 22 2017 13:35
@galileopy yeah they're brilliant for a certain audience, and not for another audience
Michael Rosata
@mrosata
May 22 2017 13:36
I have that link. I've had it for awhile but didn't actually realize who's repo it was until last night ironically
Denis Stoyanov
@xgrommx
May 22 2017 13:37

@mrosata

dropWhileM' :: (Monad m) => (a -> m Bool) -> [a] -> m [a]    
dropWhileM' p = para psi where
  psi = \case
    Nil -> return []
    Cons x (xs, ys) -> (\flg -> if flg then ys else return $ x:xs) =<< p x

example with paramorphism

Michael Rosata
@mrosata
May 22 2017 13:37
It's quite the list, have you read each article top to bottom?
Jonah
@jonahx
May 22 2017 13:37
:cake: i think ramda’s docs are good. i think the hard problem (which goes far beyond ramda), is to how make the functions searchable by use case. ie, to take the last example, to allow someone new to ramda to find evolve as the answer to his problem without asking on gitter.
Denis Stoyanov
@xgrommx
May 22 2017 13:37
@mrosata I spend some time with Kmett's recursion-schemes
Galileo Sanchez
@galileopy
May 22 2017 13:38
is there a way to run javascript inside MS Access?
Just read the whole docs?
Is not that long, or you know you can use the filter thing
Function yields HOF, Object yields all stuff that you can use with functions
Denis Stoyanov
@xgrommx
May 22 2017 13:40
@mrosata also if we will be to use Identity with dropWhileM' we can get dropWhile :smile:
Michael Rosata
@mrosata
May 22 2017 13:40
@xgrommx that's what I'll do. I didn't realize the awesome-functional-programming had multiple lists
Jonah
@jonahx
May 22 2017 13:40
@mrosata yeah stuff like that is helpful, but still not a true solution to the problem. you are asked to scan an index of descriptions and to find your use case among them. this is 1. rather inefficient 2. for the broader problem, as the number of functions increases, intractable.
Denis Stoyanov
@xgrommx
May 22 2017 13:42
@mrosata anyway I really like RS
Michael Rosata
@mrosata
May 22 2017 13:42
that sort of makes sense, like I said, I don't understand cata, but it feels almost like the opposite of bringing a value into a Functor. I realize that statement is probably wrong
James Forbes
@JAForbes
May 22 2017 13:42
Reading the entire docs doesn't fix the problem. The problem is 2 very different schools of thought. And teaching requires adapting to whatever existing mental models someone has.
Jonah
@jonahx
May 22 2017 13:43
@JAForbes that’s a good point
Denis Stoyanov
@xgrommx
May 22 2017 13:44
@mrosata u also should try it! Algebra of Functor is awesome
and Fix x ~ x
James Forbes
@JAForbes
May 22 2017 13:44
Even more broadly, communication depends on existing mental models
Michael Rosata
@mrosata
May 22 2017 13:44
I definitely will
James Forbes
@JAForbes
May 22 2017 13:44
Thanks @jonahx :)
Jonah
@jonahx
May 22 2017 13:45
@JAForbes and yes i agree, the problem as it relates to FP newbies is only a subset of a more general communication difficulty
kind of great one for illustrating the general problem, in fact
Michael Rosata
@mrosata
May 22 2017 13:46
The article I have up now is discussing Fix, defining Natural numbers as a recursive scheme. Probably where I'll have to leave it until tonight though. Since someone somewhere is paying me to do work
Denis Stoyanov
@xgrommx
May 22 2017 13:49
@mrosata this?
data Nat = Zero | Succ Nat deriving Show
data NatF a = ZeroF | SuccF a deriving (Show, Functor, Foldable, Traversable)

type instance Base Nat = NatF

instance Recursive Nat where
  project = \case
    Zero -> ZeroF
    Succ a -> SuccF a

instance Corecursive Nat where
  embed = \case
    ZeroF -> Zero
    SuccF a -> Succ a
James Forbes
@JAForbes
May 22 2017 13:50

I think a lot of OO people are concerned that learning FP means throwing away existing knowledge, they may consider themselves quite proficient in. Hence ego entering into discussions when bridging the gap.

But its not true, if anything its a refinement process, its making things more explicit. And there existing knowledge may at times give them insights that others may not have; cross pollination.

If someone lands on the ramda docs, that isn't apparent at all. Its therefore extremely intimidating. But if you can say "hey you know iterators, lets refine that" or "you know decorators, lets generalize that" or "you know types, well what are types anyways?"

Instead of {k: (v → v)} → {k: v} → {k: v} :D

Its also really hard to teach the OO crowd without an example that is either from real world code, or mimics real world code. Ramda examples tends to simply prove the functions does what its type signature says. Often via maths.
Denis Stoyanov
@xgrommx
May 22 2017 13:52
@mrosata about Fix x ~ x as I remember it is Lambek's lemma
https://www.youtube.com/watch?v=zkDVCQiveEo
James Forbes
@JAForbes
May 22 2017 13:52
And its not to say that's bad, that's really good if you are already sold on ramda / FP etc
Denis Stoyanov
@xgrommx
May 22 2017 13:53
@mrosata If u have some question, ping me in private room
Michael Rosata
@mrosata
May 22 2017 13:54
@xgrommx it's close to that example. I'm still in the early part of the article. https://medium.com/@jaredtobin/practical-recursion-schemes-c10648ec1c29 - I'll watch that video while I work (and probably again later). I will have some questions eventually, thank you
Jonah
@jonahx
May 22 2017 13:55
@JAForbes indeed function signatures have probably intimidated as many newcomers as anything about FP. which on one hand is understandable, and otoh extremely unfortunate, since they’re so simple and useful once you do understand them
James Forbes
@JAForbes
May 22 2017 13:56

Its also really hard to teach the OO crowd without an example that is either from real world code, or mimics real world code. Ramda examples tends to simply prove the functions does what its type signature says. Often via maths.

Dr Boolean is a great example of someone who demonstrates abstract concepts with concrete real world examples. That example that teaches Semigroups by merging user accounts, every person I've shown that to immediately saw the value and got excited. And terminology etc doesn't bother them once they see value.

@jonahx yeah I think the signatures are a lot like the terminology, the moment they know there's going to be value in following along, they do. But you have to start with "you can use this to do <practical non strawman example>"
E.g. look how the mithril community took to streams once they saw how it solves the cross component communication problem, which in many respects was the problem.
Now you can say Functor all day long and no-one cares
And that is not an FP community
Jonah
@jonahx
May 22 2017 14:00
@JAForbes i think the most convincing method, if someone is open to it, is to take some piece of their real world code and rewrite it in the functional style. when they see it collapse by 50% or more, and the algorithmic essence emerge out of what was visual noise and boilerplate, only the most close minded dig in and start spouting philosophical about reasons they still prefer the original.
Jordy Vialoux
@JordyVialoux
May 22 2017 14:00
test
James Forbes
@JAForbes
May 22 2017 14:03

@jonahx I've found FP code isn't always shorter, but its highly decoupled and simpler.

I mean, it certainly can be shorter, and often is. But I wish less value was placed on LOC in general.

e.g. in http://james-forbes.com/?/posts/versatility-of-array-methods the versions that just use array methods is often a touch longer, but its a lot simpler.
Michael Rosata
@mrosata
May 22 2017 14:04
@JAForbes agreed. A lot of times the part doing the work that was refactored is shorter but there's a lot more code behind it. As you say though, it's decoupled, generalized and so it becomes reusable (sometimes)
James Forbes
@JAForbes
May 22 2017 14:05
Yeah exactly, often you start writing new npm modules by accident because the abstraction boundaries become clear automatically
Jonah
@jonahx
May 22 2017 14:08
@JAForbes certainly you’re correct that there are deeper reason than LOC to prefer it. but i find the LOC as a heuristic usually quite reliably correlates with quality and simplicity. and its advantage is that its much simpler to see and understand than higher-level concepts like coupling. so i think i’d actually disagree that less emphasis should be put on it. because if i’m tasked with convincing someone of the merits of FP, my job will be vastly easier if I’m working with someone already convinced of the benefits of terse code.
James Forbes
@JAForbes
May 22 2017 14:10
haha ok agree to disagree
Jonah
@jonahx
May 22 2017 14:10
:+1:
James Forbes
@JAForbes
May 22 2017 14:11
I trust flat code more as a heuristic than LOC
but I don't have hard data :D
Jonah
@jonahx
May 22 2017 14:12
@JAForbes yes flat is another good heurisitc. switching gears, been meaning to ask you, have you used meiosis yet on a project? i just started delving it into this weekend and was super impressed by it. i think i’m going to use it on my current project.
James Forbes
@JAForbes
May 22 2017 14:12
but if I see a refactor and its deeply nested, but less code, I'd be more concerned, than a refactor that is more LOC but flat
I haven't used it, but have been following it
yeah really interesting ideas
Jonah
@jonahx
May 22 2017 14:13
@JAForbes yeah we can agree on the latter point (for some reasonable definition of “more LOC”)
James Forbes
@JAForbes
May 22 2017 14:13
yeah ok then we agree :D
if its way more LOC then its a problem...
but then again, I'm using sanctuary-def in application code, and those type definition double LOC, but make for way simpler function bodies, and acts as documentation
but its so flat :D
Jonah
@jonahx
May 22 2017 14:15
@JAForbes absolutely to the above. i’d maybe even say that any LOC you can push into a type definition i’ll give you for free.
James Forbes
@JAForbes
May 22 2017 14:16
yeah agreed again
Matej Bransky
@MatejBransky
May 22 2017 18:03
Hi, is there any function for appending values from array to objects with specific key? Example:
// => inputs
const marks = ['X', 'O']
const settings = {
  players: [
    { name: 'A', mark: '', score: 0 },
    { name: 'B', mark: '', score: 0 }
  ],
  ai: true,
  ...
}

// => result
const newSettings = {
  players: [
    { name: 'A', mark: 'X', score: 0 },
    { name: 'B', mark: 'O', score: 0 }
  ],
  ai: true,
  ...
}
Rick Medina
@rickmed
May 22 2017 18:45
@ram-bot
over(lensProp('players'), zipWith(set(lensProp('mark')), marks))({
  players: [
    { name: 'A', mark: '', score: 0 },
    { name: 'B', mark: '', score: 0 }
  ],
  ai: true
})
@ram-bot
over(lensProp('players'), zipWith(set(lensProp('mark')), ['X', 'O']))({
  players: [
    { name: 'A', mark: '', score: 0 },
    { name: 'B', mark: '', score: 0 }
  ],
  ai: true
})
:(
Matej Bransky
@MatejBransky
May 22 2017 18:49
@rickmed thanks!
Joey Figaro
@joeyfigaro
May 22 2017 21:00
anyone have any tips on how I would check an array of bools and check if all values are true? Need to return true if all are true, and false if there's one or more that are false.
Brad Compton (he/him)
@Bradcomp
May 22 2017 21:02
@ram-bot
R.all(R.identity, [true, true, true, true]);
R.all
Looks like the ram bot is down, but there you go!
Joey Figaro
@joeyfigaro
May 22 2017 21:07
Thanks @Bradcomp
Brad Compton (he/him)
@Bradcomp
May 22 2017 21:08
You could do R.all(R.equals(true), [/**/]) if you wanted to be more explicit in your accept criteria
Joey Figaro
@joeyfigaro
May 22 2017 21:15
Oo, nice - I do like that more.
Denis Stoyanov
@xgrommx
May 22 2017 21:22
reduce(and, true, [true, true, true, true, false])