These are chat archives for ramda/ramda

17th
Jul 2018
Juho Hautala
@vastus
Jul 17 2018 07:16
I wrote a capitalising function using ap but I’m wondering if there’s a more clever way to do it?
const capitalize = ap(compose(concat, toUpper, head), compose(toLower, tail))
Vesa Karvonen
@polytypic
Jul 17 2018 07:36
Well, I wouldn't call this clever:
const capitalize = pipe(toLower, replace(/^./, toUpper))
Dana Krizsan
@Danapise_twitter
Jul 17 2018 08:09
Get ready to LambdUp again!
Reason, ClojureScript, Elm, F#, Elixir. With an emphasis on front-ends. For any dev—from beginner to expert.
FB event: https://www.facebook.com/events/634968546860702/
Website: https://www.lambdup.io/
Aj Almacin
@ajalmacin_twitter
Jul 17 2018 14:54
Hi everyone I am wondering if there is a cleaner way to do this. Thanks
const data = [
  {a: 1, b: 2, c: 3},
  {a: 2, b: 3, c: 4},
  {a: 3, b: 4, c: 5},
  {a: 4, b: 5, c: 6},
  {a: 5, b: 6, c: 7},
  {a: 6, b: 7, c: 8},
  {a: 7, b: 8, c: 9, d: 10}
]

R.pipe(
  R.reduce(R.mergeWith(R.add), {}),
  r => R.assoc('grandTotal', R.pipe(R.values, R.sum)(r), r)
)(data)

// Expected
// {a: 28, b: 35, c: 42, dTotal: 10, grandTotal: 115}
Jacob Bogers
@Jacob_Bogers_twitter
Jul 17 2018 19:29
@lax4mike that example is from the doc website https://ramdajs.com/docs/#chain, I didnt make that up, yes I can read what r.chain does, and yes, I understand why that example works (now)
Mike Lambert
@lax4mike
Jul 17 2018 20:47
oh, that is in the docs. I don't understand that
Mike Lambert
@lax4mike
Jul 17 2018 21:05
i see this (https://github.com/ramda/ramda/blob/v0.25.0/source/chain.js#L31-L33) but there is no documentation about this behavior in the ramda docs, or in the fantasy land spec
Jacob Bogers
@Jacob_Bogers_twitter
Jul 17 2018 21:07
Mike Lambert
@lax4mike
Jul 17 2018 21:08
can you explain?
Jacob Bogers
@Jacob_Bogers_twitter
Jul 17 2018 21:09
I have no idea, I dont even know what "Maybe" means
is that from a library?
Mike Lambert
@lax4mike
Jul 17 2018 21:09
i'm asking about the R.chain example
ah
ok
Mike Lambert
@lax4mike
Jul 17 2018 21:09
yeah, Maybe is an abstract data type from another library
crocs, or folktale, or monet, etc
Jacob Bogers
@Jacob_Bogers_twitter
Jul 17 2018 21:10
r.chain( f1, f2)( data )
pseudocode
f1(f2(data),data)
Mike Lambert
@lax4mike
Jul 17 2018 21:10
right, i see that in the code, but i don't know why that's a thing
Jacob Bogers
@Jacob_Bogers_twitter
Jul 17 2018 21:11
yeah it seems to be a weird thing in the ramda code
if you put in 2 functions it will act like that
Mike Lambert
@lax4mike
Jul 17 2018 21:11
i think it has to do with something like that Function is a monad, but i'm not sure
Jacob Bogers
@Jacob_Bogers_twitter
Jul 17 2018 21:11
normally it takes 1 function
ok whats a monad
airity 1?
arity
Mike Lambert
@lax4mike
Jul 17 2018 21:12
a monad is an object that has a .map and .chain method
chapter 9 is about modads
but those videos go right into functors and monads
Jacob Bogers
@Jacob_Bogers_twitter
Jul 17 2018 21:14
thanks for the links
Jacob Bogers
@Jacob_Bogers_twitter
Jul 17 2018 21:19
must I learn haskell first to fully understand ramda
?
Brad Compton (he/him)
@Bradcomp
Jul 17 2018 23:24

I don't think it's necessary to understand Haskell to understand Ramda. There are some parts of Ramda that rely on knowledge of the fantasy-landspec, which is based in category theory. I think to have a full understanding of functions like chain and traverse it's important to understand how the relevant type classes work, but Haskell is just one language that works with those structures.

Understanding Monads, Functors, Traversables, etc. Is really helpful when you want to dig deeper into functional programming in the style that Ramda tends to follow. That being said, there are a ton of useful utilities that don't rely on any of that stuff, and even the tricky functions can be used without understanding the underlying theory.

A good example of that would be stuff like lenses and transducers, which can be immediately helpful to a codebase, but have a deep theoretical basis for them that you don't need to know anything about.

The type signatures are similar to Haskell, but not exactly the same. There's a good article in the wiki that explains them well.