These are chat archives for ramda/ramda

23rd
Jul 2017
Rick Medina
@rickmed
Jul 23 2017 00:12
@barbiturat functors in lenses are injected with the over/view/set functions
not sure if that is what you're asking
James
@aretecode
Jul 23 2017 00:28
@JAForbes taking that last snippet and giving it some variable names
// We've got this structure Loadable Validatable Modifiable Saveable
// Loadable can be Loaded a | Loading
// Validatable, Modifiable and Saveable are binaries, so Validatable = Valid a | Invalid b as an example.
// Here I'm traversing that structure and rendering an appropriate message for different states. If I am not interested in a state, I just skip it Validatable.fromValidatable for example just skips that layer.
// We're also handling the case where we are editing nothing currently, editingToMaybe, and in that case we just skip this whole computation, and render null which the hyperscript library treats as "don't render anything"
// But we push those nulls to the edge of the composition

const load = Loadable.fold(
  Either.Left('Loading ' + label + ' Data'),
  Either.Right
)

const validate = Either.map(
  pipe(Validatable.fromValidatable, Modifiable.fromModifiable)
)

const valueIfValid = Validatable.fold(
  o => o.value,
  a => a
)

// But what's cool is,
// there are 5 or 6 different data structures this editing panel supports,
// and this section of code has 0 interest in that.
// To get a name for a given type I use $X.of( resourceName )
// which spits out a bunch of methods
// that let me treat these different data sets
// in a polymorphic manner.
// Same thing with label (which is defined out of scope).
const resourceOrValue = T(
  $X.of(resourceName).name(o),
  valueIfValid
)

const saveOrEdit = Either.map(
  Saveable.fold(
    K('Creating new ' + label),
    o => ['Editing',
      label + ':',
      resourceOrValue,
    ].join(' ')
  )
)
const maybeLoadAndValidate = Maybe.map(
  pipe(
    load,
    validate,
    saveOrEdit,
    Either.fromEither
  )
)

const heading = T(editing, pipe(
  editingToMaybe,
  maybeLoadAndValidate,
  Maybe.toNullable
))
are you still of the opinion that coming back in the future with a different mental model would invalidate the naming of those variables?
or that the original code would be easier to read, with or without the domain knowledge?
James
@aretecode
Jul 23 2017 00:36

there are assuredly better names, but minor tweaks and (for me) it's much easier to read, with that being said, for me it's also easier to read named variables than signatures with abc-xyz for example

can you tell me what method this sig is for? (*... -> a),*... -> a ?

or this sig? a => a -> a -> Boolean ?
vs (isThis, lessThanThis) -> (isThis < lessThanThis) : Boolean
Jonah
@jonahx
Jul 23 2017 02:58
@JAForbes treating the loading/loaded state as an either is clever. I think I’d lean toward code like @aretecode is suggesting most of the time, but I can see those names being noise if you’re familar with the data structures and functions.
Jonah
@jonahx
Jul 23 2017 03:04
Also not crazy about “-able” names
Gleb Bahmutov
@bahmutov
Jul 23 2017 03:27
@ram-bot
var tomato = { firstName: ' Tomato ', data: {elapsed: 100, remaining: 1400}, id:123 } var transformations = { firstName: R.trim, lastName: R.trim, // Will not get invoked. data: {elapsed: R.add(1), remaining: R.add(-1)} } R.pick(['firstName'], R.evolve(transformations, tomato))
ram-bot
@ram-bot
Jul 23 2017 03:27
{ firstName: 'Tomato' }
Gleb Bahmutov
@bahmutov
Jul 23 2017 03:27
@ram-bot
var tomato = {
  firstName: '  Tomato ',
  data: {elapsed: 100, remaining: 1400},
  id:123
}
var transformations = {
  firstName: R.trim,
  lastName: R.trim, // Will not get invoked.
  data: {elapsed: R.add(1), remaining: R.add(-1)}
}
R.pick(['firstName'], R.evolve(transformations, tomato))
ram-bot
@ram-bot
Jul 23 2017 03:27
{ firstName: 'Tomato' }
Gleb Bahmutov
@bahmutov
Jul 23 2017 03:28
sorry everyone just trying to figure good syntax for querying ram-bot (writing on Ramda lenses blog post)
@ram-bot
var tomato = {
  firstName: '  Tomato ',
  data: {elapsed: 100, remaining: 1400},
  id:123
}
var transformations = {
  firstName: R.trim,
  lastName: R.trim, // Will not get invoked.
  data: {elapsed: R.add(1), remaining: R.add(-1)}
}
R.pick(['firstName'], R.evolve(transformations, tomato))
ram-bot
@ram-bot
Jul 23 2017 03:28
{ firstName: 'Tomato' }
Denis Stoyanov
@xgrommx
Jul 23 2017 04:02
@bahmutov what do u want?)
Gleb Bahmutov
@bahmutov
Jul 23 2017 04:02
nothing, just needed a screenshot of ram-bot!
Denis Stoyanov
@xgrommx
Jul 23 2017 04:03
@ram-bot
var tomato = {
  firstName: '  Tomato ',
  data: {elapsed: 100, remaining: 1400},
  id:123
}

over(lensProp('firstName'), trim, tomato)
ram-bot
@ram-bot
Jul 23 2017 04:03
{ firstName: 'Tomato',
  data: { elapsed: 100, remaining: 1400 },
  id: 123 }
Gleb Bahmutov
@bahmutov
Jul 23 2017 04:04
yup, just was trying to remember it :) trying to describe an alternative way where you give before / after objects and the bot gives out the transformation
Denis Stoyanov
@xgrommx
Jul 23 2017 04:07
how about vertical composition?
Gleb Bahmutov
@bahmutov
Jul 23 2017 04:07
what's vertical composition?
Denis Stoyanov
@xgrommx
Jul 23 2017 04:08
(10, 'b', 20) & (_1 ~&~ _3) %~ (*3) => (30, 'b', 60)
Gleb Bahmutov
@bahmutov
Jul 23 2017 04:09
:) that is weird syntax
Denis Stoyanov
@xgrommx
Jul 23 2017 04:09
(10, ('b', 20)) & (_2 . _2) %~ (*3) => (10,('b',60))
this is horizontal composition
:point_up: July 23, 2017 7:08 AM vertical
@bahmutov haskell :smile:
Gleb Bahmutov
@bahmutov
Jul 23 2017 04:10
for plain objects I need to compute the transformation itself
Gleb Bahmutov
@bahmutov
Jul 23 2017 04:13
yup, just grab all nested properties of the object using lensPath, not just ownKeys
Denis Stoyanov
@xgrommx
Jul 23 2017 04:14
@bahmutov this is plain js, without ramda :smile:
Gleb Bahmutov
@bahmutov
Jul 23 2017 04:15
BTW change-by-example computes the transformObj given source and destination objects
Denis Stoyanov
@xgrommx
Jul 23 2017 04:22
(10, 100, 20, '5') & ((~~&~) _1 _2 _3) %~ (*3) => (30,300,60,'5') :smile:
Fred Daoud
@foxdonut
Jul 23 2017 05:38
@jonahx thanks for the mention of Meiosis :bow: as for lensProp for multiple properties, it is lensPath, wasn't sure you had gotten an answer.
Denis Stoyanov
@xgrommx
Jul 23 2017 05:39
Ramda doesn’t use Identity, Const in lens...
James
@aretecode
Jul 23 2017 06:05
@jonahx -able names as in what?
@bahmutov cool, looking forward to an article on it :+1:
Adam Szaraniec
@mimol91
Jul 23 2017 06:07
I've got some questions related to 'haskell' notation. Lets look on Reduce. Its ((a, b) → a) → a → [b] → a. Now assume that 1st function which is passed to reduce instead to accumulator, value can be curried. This will lead to ((a → b) → a) → a → [b] → a which can be wrote (probably ) as a → b → a → a → [b] → a. Now my question is, how can You know if beginning of notation a → b → a is an function which accept type a, which return function which accept type b, and return type a of function which accept type a, and return function which accept type b, which return function which accept type a ?
Other question, what is difference between => and ?
Kurt Milam
@kurtmilam
Jul 23 2017 06:32
@aretecode I assume @jonahx is referring to names like Validatable.fromValidatable and Modifiable.fromModifiable (from here).
James
@aretecode
Jul 23 2017 06:42
ahhh
I would think if they are class methods, they can compliment the class name, as Validatable.from
@kurtmilam thanks
Kurt Milam
@kurtmilam
Jul 23 2017 06:46
I think those are probably static methods.
My guess is that JAForbes is trying to figure out whether to detach them from their containers.
I say that because I have recently found myself in a similar predicament, and the names I'm using follow the same pattern: [ContainerName].[action][ContainerName].
James
@aretecode
Jul 23 2017 06:48
static methods follow the same naming concepts
Kurt Milam
@kurtmilam
Jul 23 2017 06:50
Here's the point - do you want to destructure the container and leave yourself with toShape or do you want to leave the container intact and have Shape.to?
I'm in a situation like that where I'm trying to decide which of the two styles I prefer. I'm currently leaning toward destructuring the container object and having bare functions with names like toShape, etc.
James
@aretecode
Jul 23 2017 06:51

losing the container loses a lot, for me, but I am opinionated and don't think everything-as-functional-stateless-immutable-in-every-circumstance-only-one-way approach is the one I use to solve all problems in all situations

but at the same time, you can get the best of both worlds

Kurt Milam
@kurtmilam
Jul 23 2017 06:53
I still haven't made up my mind. Although in my situation Shape in Shape.to is purely a container, it also offers a nice way to namespace related methods.
James
@aretecode
Jul 23 2017 06:55
it's the @member in docblocks :-P
Kurt Milam
@kurtmilam
Jul 23 2017 06:56
My objects look like Shape.toShape at the moment, as I focus on other questions, but in the end, one of the Shapes will be removed. I may just let the user tell the factory whether they prefer. toShape or Shape.to and transfer the work to them :D
James
@aretecode
Jul 23 2017 07:05
providing toShape = Shape.to is nice
Kurt Milam
@kurtmilam
Jul 23 2017 07:15
:thumbsup:
Kevin Wallace
@kedashoe
Jul 23 2017 15:24
@mimol91 the parentheses denote higher order functions, they are required. => is the separator between type classes and function arguments
sanctuary has a nice, short description of type signatures https://sanctuary.js.org/#types
Rick Medina
@rickmed
Jul 23 2017 16:00

Ramda doesn’t use Identity, Const in lens...

@xgrommx what do you mean?

Denis Stoyanov
@xgrommx
Jul 23 2017 16:58
@rickmed Functors
Rick Medina
@rickmed
Jul 23 2017 17:03
@xgrommx right...ramda implements classic van Laarhoven lenses, Const/Id is used
Denis Stoyanov
@xgrommx
Jul 23 2017 17:04
@rickmed hm, where?
Rick Medina
@rickmed
Jul 23 2017 17:06
@xgrommx lens function returns (functor) {...}, view/set/over calls with appropriate functor
Denis Stoyanov
@xgrommx
Jul 23 2017 17:13
okay!
In haskell I can (~&~) = liftA2(>=>), (10, ‘a’, 20) & (_1 ~&~ _3) %~ (*3), how can I do it in ramda?
Rick Medina
@rickmed
Jul 23 2017 17:25
sorry, I'm not at that haskell level yet, specially with the infinity of lens specific operators, but anyway I don't think it is 1:1 to haskell bc ramda has a simple ad-hoc Const/Id implementation (eg: F.value to extract functor value)
Denis Stoyanov
@xgrommx
Jul 23 2017 17:39
@rickmed %~ this is over