These are chat archives for ramda/ramda

26th
Aug 2016
Scott Sauyet
@CrossEye
Aug 26 2016 03:21
I've been away for a while, first with vacation, then with annoying painful dental issues. I should be back involved in Ramda stuff this weekend, but I did respond to this Stack Overflow post, and I think it would be great if others (especially with different ideas) had contributions to add.
Rick Medina
@rickmed
Aug 26 2016 04:02
I'm learning about lenses watching this Brian Lonsdorf talk https://vimeo.com/104807358, I see there is no "Lens.mapped" equivalent in ramda, I'm sure I can do it composing with map, but how?
Scott Christopher
@scott-christopher
Aug 26 2016 04:20
@rickmed
Brad Compton (he/him)
@Bradcomp
Aug 26 2016 04:20
@rickmed If you want to mess around with lenses, I think this was created in conjunction with that video: https://github.com/ramda/ramda-lens
Scott Christopher
@scott-christopher
Aug 26 2016 04:20
@ram-bot
const mapped = f => compose(Identity, map(compose(prop('value'), f)))
const l = compose(mapped, lensProp('x'), mapped)
over(l, inc, [{ x: [1, 2, 3] }, { x: [4, 5, 6] }])
ram-bot
@ram-bot
Aug 26 2016 04:20
[ { x: [ 2, 3, 4 ] }, { x: [ 5, 6, 7 ] } ]
Scott Christopher
@scott-christopher
Aug 26 2016 04:22
Just need to be mindful that it won't work with view.
Rick Medina
@rickmed
Aug 26 2016 04:27
@Bradcomp thanks!
@scott-christopher great. thanks! (anyway map/mapped denotes that is a transformation so it makes no sense with view, right? )
or maybe that is non-sense what I just said, I'm just learning this stuff :smile:
Scott Christopher
@scott-christopher
Aug 26 2016 04:48
yeah, exactly
If the only thing you know about some type is that it is a functor (i.e. it can be mapped over), then there is no way to extract the contained value (if any) out to be viewed.
Drew
@dtipson
Aug 26 2016 05:19
@derek-duncan my own take on explaining the base concept here: https://medium.com/@dtipson/everything-reduced-transducers-in-javascript-8ea3459bc7f9#.c985kuhrj
Risto Novik
@riston
Aug 26 2016 12:39
hello
how to zip array with some constant value ["a", "b"] -> { a: true, b: true} ?
Aaron Mc Adam
@aaronmcadam
Aug 26 2016 12:41
You could use T() at least, which always returns true
This message was deleted
@ram-bot
mapObjIndexed(T, ['a', 'b'])
@ram-bot mapObjIndexed(T, ['a', 'b'])
ram-bot
@ram-bot
Aug 26 2016 12:43
{ '0': true, '1': true }
Aaron Mc Adam
@aaronmcadam
Aug 26 2016 12:47
@ram-bot zipObj(['a', 'b'], T)
ram-bot
@ram-bot
Aug 26 2016 12:47
{}
Risto Novik
@riston
Aug 26 2016 12:48
mm how to just create tuples [["a", true], ["b", true]] ?
R.map(x => [x, true], ['foo', 'bar', 'baz']);
Aaron Mc Adam
@aaronmcadam
Aug 26 2016 12:49
ah cool
Risto Novik
@riston
Aug 26 2016 12:50
R.fromPairs(R.map(x => [x, true], ['foo', 'bar', 'baz']));
@ram-bot R.fromPairs(R.map(x => [x, true], ['foo', 'bar', 'baz']));
Aaron Mc Adam
@aaronmcadam
Aug 26 2016 12:50
backtick it for @ram-bot
Unfortunately it doesn't work when you edit
Risto Novik
@riston
Aug 26 2016 12:50
:(
Aaron Mc Adam
@aaronmcadam
Aug 26 2016 12:50
@ram-bot R.fromPairs(R.map(x => [x, true], ['foo', 'bar', 'baz']));
ram-bot
@ram-bot
Aug 26 2016 12:50
{ foo: true, bar: true, baz: true }
Risto Novik
@riston
Aug 26 2016 12:50
good
Aaron Mc Adam
@aaronmcadam
Aug 26 2016 12:51
@ram-bot R.chain(x => [x, true], ['foo', 'bar', 'baz']);
ram-bot
@ram-bot
Aug 26 2016 12:51
[ [ 'foo', true ], [ 'bar', true ], [ 'baz', true ] ]
Aaron Mc Adam
@aaronmcadam
Aug 26 2016 12:51
@ram-bot R.chain(x => [x, true], ['foo', 'bar', 'baz']);
ram-bot
@ram-bot
Aug 26 2016 12:51
[ 'foo', true, 'bar', true, 'baz', true ]
Aaron Mc Adam
@aaronmcadam
Aug 26 2016 12:52
@ram-bot R.lift(x => [x, true], ['foo', 'bar', 'baz']);
ram-bot
@ram-bot
Aug 26 2016 12:52
[Function: f1]
Aaron Mc Adam
@aaronmcadam
Aug 26 2016 12:52
I'm just playing
Risto Novik
@riston
Aug 26 2016 12:54
    const toObj = R.compose(
        R.fromPairs,
        R.map(x => [x, true])
    );
I think the map part could be written shorter way
Aaron Mc Adam
@aaronmcadam
Aug 26 2016 12:55
yeah, there's something in that
Risto Novik
@riston
Aug 26 2016 13:05
const toObj = R.compose(
   R.fromPairs,
   R.flip(R.xprod)([true])
 );

toObj([1,2,3,4])
argh the flip >D
Aaron Mc Adam
@aaronmcadam
Aug 26 2016 13:23
I can't figure out how to make the xprod part point free :(
Denis Stoyanov
@xgrommx
Aug 26 2016 13:31
@aaronmcadam what is result should be?
Aaron Mc Adam
@aaronmcadam
Aug 26 2016 13:32
Denis Stoyanov
@xgrommx
Aug 26 2016 13:43
@aaronmcadam compose(mergeAll, lift(objOf))([1,2,3,4], [true])
Aaron Mc Adam
@aaronmcadam
Aug 26 2016 13:44
what if you wanted to hide the [true] part?
as in, be able to call the function with just the array
Denis Stoyanov
@xgrommx
Aug 26 2016 13:44
@aaronmcadam compose(mergeAll, flip(lift(objOf))([true]))([1,2,3,4])
Matt McFarland
@MattMcFarland
Aug 26 2016 13:50
Is there a zipObj that works in the opposite direction?
Aaron Mc Adam
@aaronmcadam
Aug 26 2016 13:50
Have you tried flipping it @MattMcFarland ?
Matt McFarland
@MattMcFarland
Aug 26 2016 13:53
@aaronmcadam Do you mean something like so? R.flip(R.zipObj)({a: 1, b: 2, c: 3})
Aaron Mc Adam
@aaronmcadam
Aug 26 2016 13:53
@ram-bot R.flip(R.zipObj)({a: 1, b: 2, c: 3})
ram-bot
@ram-bot
Aug 26 2016 13:53
[Function]
Denis Stoyanov
@xgrommx
Aug 26 2016 13:53
@MattMcFarland zip works only with lists
Aaron Mc Adam
@aaronmcadam
Aug 26 2016 13:54
@ram-bot R.flip(R.zipObj)(['a', 'b', 'c'], [1, 2, 3])
ram-bot
@ram-bot
Aug 26 2016 13:54
{ '1': 'a', '2': 'b', '3': 'c' }
Aaron Mc Adam
@aaronmcadam
Aug 26 2016 13:55
@MattMcFarland See above ^^
Denis Stoyanov
@xgrommx
Aug 26 2016 13:55
@aaronmcadam what is the problem?
Aaron Mc Adam
@aaronmcadam
Aug 26 2016 13:55
Eh?
No problem for me
Matt McFarland
@MattMcFarland
Aug 26 2016 13:55
Sorry my mistake. I'm looking to take an object like
{ '1': 'a', '2': 'b', '3': 'c' } => [[1,'a'],[2,'b'],[3,'c']]
Aaron Mc Adam
@aaronmcadam
Aug 26 2016 13:56
@ram-bot toPairs({ '1': 'a', '2': 'b', '3': 'c' })
ram-bot
@ram-bot
Aug 26 2016 13:56
[ [ '1', 'a' ], [ '2', 'b' ], [ '3', 'c' ] ]
Matt McFarland
@MattMcFarland
Aug 26 2016 13:57
Awesome that is what I was looking for. Thanks!
Aaron Mc Adam
@aaronmcadam
Aug 26 2016 13:57
no worries!
Vladimir Starkov
@iamstarkov
Aug 26 2016 14:32
hi, everyone, today i want to share "#2 practical into" of my "real world fp" workshop series
Slides are here http://iamstarkov.com/fp-js-workshop/02-practical-intro/
Colleagues were happy to see how useful const log = R.tap(console.log.bind(console)) can be inside of their R.pipe(…) functions.
Especially with tests running in watch mode.
TJ Peden
@tjpeden
Aug 26 2016 15:10
Are there some good examples of the sorts of things lens is good for?
Aaron Mc Adam
@aaronmcadam
Aug 26 2016 15:11
TJ Peden
@tjpeden
Aug 26 2016 15:11
Cool thanks!
Derek Duncan
@derek-duncan
Aug 26 2016 15:39

got a question about the last example in this blog (from documentation), and wondering if anyone can help. http://randycoulman.com/blog/2016/06/07/thinking-in-ramda-partial-application/
Here's the code from the last example:

const publishedInYear = curry((year, book) => book.year === year)

const titlesForYear = curry((year, books) =>
  pipe(
    filter(publishedInYear(year)),
    map(book => book.title)
  )(books)
)

how would you use titlesForYear in a compose pipeline? here's what I'm picturing:

// const getBooks = () => [{...}, {...}, {...}];
// const getPopularYearFromBooks = filter(compose(gt(4), (prop('rating')));
const titlesForYearFromBooks = compose(titlesForYear, getPopularYearFromBooks, getBooks);

I need to pass both the books and year into titlesForYear, but how do I do that at the end of the compose pipeline?

Derek Duncan
@derek-duncan
Aug 26 2016 15:45
the example may be a little flawed, but my main question is how to pass multiple arguments to a function from the result of previous functions in compose.
Brad Compton (he/him)
@Bradcomp
Aug 26 2016 15:47
@derek-duncan Every function after the first one in compose has to be unary, but that doesn't mean you're out of luck.
const titlesForYearFromBooks = R.useWith(titlesForYear, [R.identity, getPopularYearFromBooks])(year, books)
So if you feel the need to go point free (which isn't necessary) you can use useWith to pass particular parameters through some functions before applying your final transformation
Disclaimer: useWith can really obfuscate your code if overused.
Derek Duncan
@derek-duncan
Aug 26 2016 15:51
ah, that's pretty cool
so for the sake of clarity, sacrificing pointfree functions may be the better option here?
Brad Compton (he/him)
@Bradcomp
Aug 26 2016 16:14
Often times that's the case, but it depends on a lot of factors of course
Derek Duncan
@derek-duncan
Aug 26 2016 16:15
@Bradcomp :+1: thanks for the help :)
TJ Peden
@tjpeden
Aug 26 2016 18:58
R.into has me all kinds of confused
TJ Peden
@tjpeden
Aug 26 2016 19:13
Nope, transducers have me all kinds of confused
into is pretty straight forward really lol
LeonineKing1199
@LeonineKing1199
Aug 26 2016 20:36
Would there be any interest in adding multi-array support for some of Ramda's List-centric functions? For example, if map supported a variable number of arrays and the callback signature was updated to reflect the variable number of arrays.
LeonineKing1199
@LeonineKing1199
Aug 26 2016 21:01
To be a bit more specific, imagine map(add, arr1, arr2) so if we had:
const a = [0, 1, 2];
const b = [3, 4, 5];

map(add, a, b)
// => [3, 5, 7]
Denis Stoyanov
@xgrommx
Aug 26 2016 21:12
@LeonineKing1199 zipWith
LeonineKing1199
@LeonineKing1199
Aug 26 2016 21:12
That'd be hecka inefficient.
Denis Stoyanov
@xgrommx
Aug 26 2016 21:12
@LeonineKing1199 ?
LeonineKing1199
@LeonineKing1199
Aug 26 2016 21:15
Creating an array of tuples is more costly than just doing a single-pass over a series of aligned arrays.
I know JS allows poly-typed arrays but for some reason, I feel guilty doing it and would prefer mono-typed arrays always over emulating tuples in a language without tuples.
Brad Compton (he/him)
@Bradcomp
Aug 26 2016 21:21
@LeonineKing1199 Like this? http://goo.gl/XBTh8J
LeonineKing1199
@LeonineKing1199
Aug 26 2016 21:24
I was thinking more or less of extending this particular section of the implementation.
Denis Stoyanov
@xgrommx
Aug 26 2016 21:26
@LeonineKing1199 functor should has only one morphism and only one category
LeonineKing1199
@LeonineKing1199
Aug 26 2016 21:29
Sure, functors should obey that but a transformation function has no such need.
It's rather simple to describe a mapping between mutliple sets into one set.
Plus, it'd be hecka useful.
LeonineKing1199
@LeonineKing1199
Aug 26 2016 21:44
Basically, this would be the source code changes: http://goo.gl/U9a6SN
Toss in a little vanilla JS in there and bada bing bada boom, you have non backward-breaking changes to the core!
It's more vanilla to just use this too: result[idx] = fn.apply(fn, args);
Ryan Zeigler
@rzeigler
Aug 26 2016 23:05
There are other ways that don't involve tupling or variadic functions.