These are chat archives for ramda/ramda

24th
Mar 2017
Raine Virta
@raine
Mar 24 2017 10:39
@ram-bot status
ram-bot
@ram-bot
Mar 24 2017 10:39
All systems operational.
Johnny Hauser
@m59peacemaker
Mar 24 2017 12:10
How do you actually get the value out of a functor? (not just lift to modify it)
doSomething(S.Just(15)) // => 15
Daniel Skelton
@dskelton-r7
Mar 24 2017 12:18
data.maybe has a method getOrElse
Maybe(null).getOrElse(10)
For sanctuary could you do Maybe(value).chain(identity)
Ah wait, its fromMaybe()
Johnny Hauser
@m59peacemaker
Mar 24 2017 12:27
I'm extremely new to this
how do you make Just into a Maybe?
I'm doubly confused that there is Maybe.Just
perhaps I am mixing up things in the REPL
Piet Vandeput
@piet-v
Mar 24 2017 12:29
isn't Just subclass of Maybe?
James Forbes
@JAForbes
Mar 24 2017 12:29
@m59peacemaker Just is a Maybe, just like true is a boolean
Piet Vandeput
@piet-v
Mar 24 2017 12:30
Maybe is either a Just or Nothing right?
James Forbes
@JAForbes
Mar 24 2017 12:30
Maybe is Either! :D
type Maybe = Just a | Nothing
Piet Vandeput
@piet-v
Mar 24 2017 12:30

monadCeption

James Forbes
@JAForbes
Mar 24 2017 12:30
Yes! :D
Johnny Hauser
@m59peacemaker
Mar 24 2017 12:31
I suppose where I am lost is
chain(identity, Maybe.of(15)) // => 15
chain(identity, S.Just(15))  // => []
James Forbes
@JAForbes
Mar 24 2017 12:32
@m59peacemaker ok so you can't chain identity, that's cheating :D
Johnny Hauser
@m59peacemaker
Mar 24 2017 12:32
I was decent enough to think "chain(identity)` earlier before I asked, but when I got an array, I assumed I was a big dummy
:(
Daniel said I could!
James Forbes
@JAForbes
Mar 24 2017 12:32
if you use chain your visitor function should return a Monad of the same chain
Johnny Hauser
@m59peacemaker
Mar 24 2017 12:32
heh
if you'd be so kind, lemme eliminate the X/Y here
I watched the talk on transducers why Rich Hickey and oh my did it change my life
they need a way to short circuit, for which he introduces the concept of a "Reduced" type
Reduced is a functor that holds the result
James Forbes
@JAForbes
Mar 24 2017 12:35
is it in clojure? I didn't know that
Johnny Hauser
@m59peacemaker
Mar 24 2017 12:35
but I was thinking it should be something else?
James Forbes
@JAForbes
Mar 24 2017 12:36
so few things to note
Johnny Hauser
@m59peacemaker
Mar 24 2017 12:36
There's no such thing as a standard method for unwrapping?
James Forbes
@JAForbes
Mar 24 2017 12:36
oh there is, but let me unpack it a bit
Johnny Hauser
@m59peacemaker
Mar 24 2017 12:37
I literally thought "why have unreduced(reduced) when you could have chain(identity, reduced)"
James Forbes
@JAForbes
Mar 24 2017 12:37
We often say, x is a Maybe. I say this myself.
but really its more accurate to say x has a Maybe
or even x can be a Maybe
Johnny Hauser
@m59peacemaker
Mar 24 2017 12:38
any anything can be in the fp world?
James Forbes
@JAForbes
Mar 24 2017 12:38
so just because x is Functor, doesn't mean its not also something else
Johnny Hauser
@m59peacemaker
Mar 24 2017 12:38
Reduced can be/have a Maybe?
James Forbes
@JAForbes
Mar 24 2017 12:38
so something can be a Functor, but could also for example be Foldable
so what we can say is: we can't extract a value out of a Functor using the interface of a Functor only
but just because something is a Functor, doesn't mean its not also some other type where we can extract its value.
Johnny Hauser
@m59peacemaker
Mar 24 2017 12:39
yup yup makes sense!!
James Forbes
@JAForbes
Mar 24 2017 12:39
A functor, or a monad alone, don't alone to extract the inner value directly. But that's a good thing
Johnny Hauser
@m59peacemaker
Mar 24 2017 12:39
So how do you feel about that library's unreduce ?
Couldn't it return a Maybe instead?
crud
I meant
James Forbes
@JAForbes
Mar 24 2017 12:40
It tells us, hey if you want to access this value, there's a safe standard way that allow's this type to do it's thing with you worring about it, e.g. map/chain
so the fact its a functor, is kind of like saying: if you want to safely access this, use it as a functor
Johnny Hauser
@m59peacemaker
Mar 24 2017 12:40
A Reduce that is a Maybe, and then unwrap is with a fromMaybe
James Forbes
@JAForbes
Mar 24 2017 12:41
yeah sure, next thing to unpack is
Johnny Hauser
@m59peacemaker
Mar 24 2017 12:42
maybe unreduce is ok
James Forbes
@JAForbes
Mar 24 2017 12:42
Different types might need different strategies to extract a value
e.g. maybe it contains multiple values, or maybe its async, or maybe there's no value at all!
So having a standard way to unwrap values is not going to work, but there are standard ways to get values out
one way is reduce/fold
third thing: it should be rare we need to unwrap a Monad, or a Functor, there's very few times we're we'd need or want to do that

The only time really, is when we want to interact with an interface that doesn't or shouldn't know about our internal types.

But anything within our app, or library, can be done while staying within the safety net of map or chain

ok that's my rant :)
Johnny Hauser
@m59peacemaker
Mar 24 2017 12:48
Doesn't Reduced just have that one purpose, though?
maybe you can help me with terms
James Forbes
@JAForbes
Mar 24 2017 12:48
yeah sorry I was speaking broadly
Johnny Hauser
@m59peacemaker
Mar 24 2017 12:49
I haven't figured out the difference between a transducer and transformer
What is mapping ?
I can write the dern thing but don't know the terms haha
James Forbes
@JAForbes
Mar 24 2017 12:49
my transducer knowledge is pretty weak, but here goes :D
Johnny Hauser
@m59peacemaker
Mar 24 2017 12:50
const mapping = curry((fn, step, r, x) => step(r, fn(x)))
I know, currying is probably not ok there
still experimenting with that
James Forbes
@JAForbes
Mar 24 2017 12:50
So clojure already had functions called map for specific data types
Johnny Hauser
@m59peacemaker
Mar 24 2017 12:50
yes. I like the ing naming anyway
James Forbes
@JAForbes
Mar 24 2017 12:50
transducers define these operations in generic ways that abstract over the specfic type
mapping (I think) is just map build as a composable transducer
they just needed another name to say "hey this is a transducer map"
Johnny Hauser
@m59peacemaker
Mar 24 2017 12:51
I think Rich said that my mapping there returns the transducer
now that you mention it
the transducer, according to him, is the thing that takes step
always takes the single argument "step" and returns a function that does the thing = transducer
so what calls mapping though?
James Forbes
@JAForbes
Mar 24 2017 12:52
a transformer, is what we'd normally call a visitor function, but specific to transducers (again I think)
Johnny Hauser
@m59peacemaker
Mar 24 2017 12:52
hm...
(step) => {} transformer?
maybe he mis-spoke or I mis-remember?
oh doh
step => {} is the transducer
(r, x) => {} is the visitor/transformer ?
I'm just guessing wildly lol
things make sense and then they don't
James Forbes
@JAForbes
Mar 24 2017 12:57
yeah same
I've understood and then not understood transducers several times, I think this post is helpful though: http://jlongster.com/Transducers.js--A-JavaScript-Library-for-Transformation-of-Data
Johnny Hauser
@m59peacemaker
Mar 24 2017 13:08
It calls one of the things the reducing function
James Forbes
@JAForbes
Mar 24 2017 13:09
the post?
From my understanding, almost every component within a transducer is a reducer, the thing that throws me with transducers isn't the concepts or the usage, its just the names.
aggregation/transformation etc its all reducers
Theofanis Despoudis
@theodesp
Mar 24 2017 13:15
hey guys do you know why Ramda Fantasy Future does not return anything when it gets forked?
I was trying to do a cancel for a future by calling it like in fluture https://github.com/fluture-js/Fluture#future but it turns out it returns nothing
Bravi
@Bravilogy
Mar 24 2017 13:36
posted another example. Perhaps it could've been a cleaner ramda code, but .. tried my best :D
http://envious-smile.surge.sh/#/examples/chain-of-events
Aaron
@genetique-techno
Mar 24 2017 13:44

Hi. Can anyone help me understand why this piece of code does not work?

r.converge( r.compose,
  r.map( p => r.over( r.lensPath(p), r.negate ), [["stat"], ["beer"]])
)({stat:1,beer:2})

My expectation is that it will produce a compose that is filled with r.over (each with a different path), and when an object is passed in all the properties in the object will be operated on.

Instead I get this error: First argument to _arity must be a non-negative integer no greater than ten
If this is the wrong place to ask for help I apologize
Matthew Willhite
@miwillhite
Mar 24 2017 14:09
I believe converge expects the length of the second argument to match the arity of the fn provided in the first: converge(fnWithArityOfTwo, [arg1, arg2])
Piet Vandeput
@piet-v
Mar 24 2017 14:35
anyone know how I can simplify this?
const object = {a: {f:'g'}, b: 'd'}
// pathFrom :: {a:b} => ['a'] => b
const pathFrom = R.flip(R.path);
// pathFrom :: {a:c, b:d} => [['a'], ['b']] => [c, d]
const pathsFrom = R.useWith(R.map, [pathFrom, R.identity]);

pathsFrom(object, [['a', 'f'], ['b']])
aka, any way to get rid of that pathFrom function?
Aaron
@genetique-techno
Mar 24 2017 14:39
@miwillhite thanks!
Piet Vandeput
@piet-v
Mar 24 2017 15:09
well I've stumbled on a different problem atm. Anyone here want to have a go at helping me build a bad-ass function?
const object = {a: 1,
 b: {
   content: [
     {value: ''},
     {value: 'hi'}
   ]
 },
 c: 3,
 d: {
   e: {
     content: [
       {value: ''},
       {value: 'hi'}  
     ] 
   }
 }
}
const paths = [ ['b', 'content'], ['d','e','content'] ]
const valueFilter = R.filter(R.prop('value'));
const evolvePathsWith = R.identity //???
evolvePathsWith(valueFilter, paths, object)
problem: I have an object where I need to evolve several paths
not sure what best approach is here?
basically need to filter out all the objects with empty values at the given paths
Galileo Sanchez
@galileopy
Mar 24 2017 15:17
@piet-v
Piet Vandeput
@piet-v
Mar 24 2017 15:18
oh that's how u nest in evolve x)
thx!
Piet Vandeput
@piet-v
Mar 24 2017 15:25
any way to make if more dynamic though? I have an object where I have to filter about 20 of these paths, kinda painful having to manually link the filter function in the evolve object
Daniel Tsui
@sdtsui
Mar 24 2017 15:51

Hey all,

I’d like to perform existence checks for a function before invoking, and was hoping to make this code pointfree. Any suggestions?
http://bit.ly/2neQlqt

Thanks!

Henrik Sommerland
@TheGrandmother
Mar 24 2017 18:37
Hello!
I'm trying to implement a repeatWith function that behaves similar to replicateM in Haskell.
Just one quick question: How do you specify the type for a nullary function?
Denis Stoyanov
@xgrommx
Mar 24 2017 18:50
@TheGrandmother repeatM = n => m => sequence(of, repeat(m, n))
Henrik Sommerland
@TheGrandmother
Mar 24 2017 18:51
@xgrommx I know how it is done in Haskell but I was wondering how you represented it in the documentation.
Although i found that * -> a appears to be the notation used in the documentation
Kurt Milam
@kurtmilam
Mar 24 2017 22:02
@sdtsui R.compose( R.equals( 'Function' ), R.type, R.prop( 'getBoundingClientRect' ) )
There are a number of opportunities to improve that code, making it more pointfree.
Piet Vandeput
@piet-v
Mar 24 2017 22:35
uhm very confused atm about R.intersectionWith
if two elements are identified to be the same by the comparator
which element is supposed to be returned? The one from list A or list B?
Brad Compton (he/him)
@Bradcomp
Mar 24 2017 22:36
The one from the shorter list :stuck_out_tongue:
I think it's getting deprecated in favor of an innerJoin function
Piet Vandeput
@piet-v
Mar 24 2017 22:36
ah balls, this explains so much
was thinking it's like merge where the second list wins x)
Brad Compton (he/him)
@Bradcomp
Mar 24 2017 22:39
There was an issue / PR about it, I can't find it ATM though
ramda/ramda#1868
There it is!
Piet Vandeput
@piet-v
Mar 24 2017 22:48
any idea when new version is getting released? shamelessly using the source till then x)
Brad Compton (he/him)
@Bradcomp
Mar 24 2017 22:54
No idea