These are chat archives for ramda/ramda

23rd
Aug 2016
Ronn
@ronnross
Aug 23 2016 02:19
HI all, I had a question earlier around matching values from two list. Here is the structure
const list1 = [
  { tag: 'ident1', text: 'some text' },
  { tag: 'indent2', text: 'some text' },
  { tag: 'indent3', text: 'more text' }]

const list2 = ['ident1']

R.intersection(list1, list2)
Some help me find this answer intersection(map(prop('tag'), list1), list2)
This gives me an array with ["indent1"]
I was hoping to get the entire object and not just the tag name.
Can someone point me in the right direction?
Syaiful Bahri
@syaiful6
Aug 23 2016 02:22
yes, it's correct. intersection A ∩ B of two sets A and B is the set that contains all elements of A that also belong to B
Ronn
@ronnross
Aug 23 2016 02:30
so would you recommend mapping back over the list to get the full object?
Syaiful Bahri
@syaiful6
Aug 23 2016 02:30
@ronnross do you want the entire object?
const list1 = [
  { tag: 'ident1', text: 'some text' },
  { tag: 'indent2', text: 'some text' },
  { tag: 'indent3', text: 'more text' }]

const list2 = ['ident1']

const predicate = R.flip(R.contains)
R.filter(R.compose(predicate(list2), R.prop('tag')), list1)
it output list like so
[{"tag": "ident1", "text": "some text"}]
Ronn
@ronnross
Aug 23 2016 02:31
Perfect!
Thank you!
This message was deleted
Syaiful Bahri
@syaiful6
Aug 23 2016 02:33
nope :smile:
Ronn
@ronnross
Aug 23 2016 02:34
Just tested it in my code and works perfect Thanks @syaiful6
Churchill Lee
@FeliciousX
Aug 23 2016 11:50
anyone uses Node.cloneNode here? to keep the immutable DOM nodes?
just wondering if it's a common thing to do
or at least, anyone uses R.assoc with DOM Nodes?
coz it always returns me a new Object instead of a DOM Node
it doesn't return me the same type :/
Aaron Mc Adam
@aaronmcadam
Aug 23 2016 12:08
It makes a shallow clone with a new object, that's why
I guess you'd need a way to pass a different class to it
or implement your own version
Julien Goux
@jgoux
Aug 23 2016 13:04
Hi
is there a function to switch on the value of a Maybe a ? I'm looking for something like fromMaybe but accepting 2 functions instead of a function + a value
S.foo(
  user => { /* do something with the user */ },
  _ => { /* do something if Nothing */ },
  Users.find(userId)
)
it's really common in PS or Haskell with destructuring on Just
Aldwin Vlasblom
@Avaq
Aug 23 2016 13:07
There is S.maybe
Julien Goux
@jgoux
Aug 23 2016 13:08
case mUser of
  Just user -> 
  Nothing ->
isn't the maybe taking a value as well ?
I'd like to pass a function for the first arg, not a value
hello btw Aldwin :D
Aldwin Vlasblom
@Avaq
Aug 23 2016 13:09
I usually do:
const create = data => ({data, iat: Date.now()});
const update = record => data => ({data: {...record.data, ...data}, iat: Date.now()});

const maybeRecord = findData();
const process = maybe(create, update, maybeRecord);

process(input);
Hey :)
Julien Goux
@jgoux
Aug 23 2016 13:11
yes I could do it that way too :smile:
Aldwin Vlasblom
@Avaq
Aug 23 2016 13:11
So far, whenever I find myself needing to "do X in case of Nothing, or Y in case of Just", I can structure the program to have a unary function for the Nothing branch, or a binary function for the Just branch.
And then just use maybe to pick the one you need, always giving you a unary function to call.
I find it one of those things Sanctuary does that forces me to structure my programs in a logical way. The function you are looking for is "weird" because it takes Void/unit as input.
Denis Stoyanov
@xgrommx
Aug 23 2016 13:31
@Avaq also maybe is fold operator for Maybe
Denis Stoyanov
@xgrommx
Aug 23 2016 13:45
@Avaq also it's a >>= for Maybe
let bindMaybe  = maybe Nothing
bindMaybe (\v -> Just $ v * 10) $ Just 20 // => Just 200
Drew
@dtipson
Aug 23 2016 20:19
@avaq I don't think I ever thought of using maybe like that, with unary func/binary func inputs for the first two arguments, instead of value, unary func: that's ingenious!
Roman Pominov
@rpominov
Aug 23 2016 21:21
Anyone know good articles that explain Either? Similar to https://fsharpforfunandprofit.com/posts/recipe-part2/
Need it for an article I working on, to put link alongside "Railway oriented programming"
Or maybe instead of "Railway oriented programming"
Brad Compton (he/him)
@Bradcomp
Aug 23 2016 21:25
@rpominov I've always enjoyed the articles accompanying Folktale: http://robotlolita.me/2013/12/08/a-monad-in-practicality-first-class-failures.html
Roman Pominov
@rpominov
Aug 23 2016 21:26
@Bradcomp Thanks, looks like a good one.
Chet Harrison
@ChetHarrison
Aug 23 2016 21:44
@rpominov this may be useful. I am calling it a validation but it's an Either https://www.youtube.com/watch?v=ZQSU4geXAxM
Ryan Zeigler
@rzeigler
Aug 23 2016 21:48
mildly confusing because validation is also a thing
Chet Harrison
@ChetHarrison
Aug 23 2016 21:55
The Validation data type is isomorphic to Either and has a Monad instance that does the same as Either
Roman Pominov
@rpominov
Aug 23 2016 21:55
@ChetHarrison Thanks. I'll check it out.
Chet Harrison
@ChetHarrison
Aug 23 2016 21:55
:+1:
it's essentially the RRO talk in JS
Roman Pominov
@rpominov
Aug 23 2016 21:59
Cool, need to watch it, but sounds like something that I need.
Roman Pominov
@rpominov
Aug 23 2016 23:57
Thanks, @rickmed