These are chat archives for ramda/ramda

19th
Dec 2017
Johnny Hauser
@m59peacemaker
Dec 19 2017 00:06
That appears to make a stream of arrays of streams, right?
I'm not needing to know "how" to do it.. I've got that already
I just don't know what to call it
and I like to look at the API other people solve the problem with and compare it with my ideas
Vasili Sviridov
@vsviridov
Dec 19 2017 00:07
ah..
not sure about that, I was googling "stream of arrays into array of streams"
Johnny Hauser
@m59peacemaker
Dec 19 2017 00:08
It's probably a pretty odd thing to do.
I'm using my rewrite of flyd, which is pretty different from other frp libs..
and using it in a state management approach that I've never seen done before and may be terrible :)
Denis Stoyanov
@xgrommx
Dec 19 2017 00:29
@m59peacemaker this impossible Async [T] -> [Async T]
Johnny Hauser
@m59peacemaker
Dec 19 2017 00:42
?
I'm doing it so I hope it's possible :)
Or I've broken the world
It's the same as partition in rxjs
I was just eating dinner. Getting back to this topic. I'm entertaining naming it partitionBy and taking a function that handles the kind of partitioning.
I think rx partition really ought to be called bipartition
Denis Stoyanov
@xgrommx
Dec 19 2017 01:10
@m59peacemaker you cannot translate Async -> Sync
Johnny Hauser
@m59peacemaker
Dec 19 2017 01:11
I don't think we're speaking about the same things
Johnny Hauser
@m59peacemaker
Dec 19 2017 01:25
@xgrommx If you know flyd, maybe this will make sense
  const partitionArray = length => source => {
    const streams = [ ...new Array(length) ].map(() => endsOn([ source.end ]) (W.Stream()))
    map
      (array => array.forEach((v, idx) => streams[idx].set(v)))
      (source)
    return streams
  }
the source stream emits an array, partitionArray takes it, makes streams that are like proxies and returns them, and when source emits, the values from that emitted array are forwarded to those new streams
Claudio Corridore
@ClaudioCorridore
Dec 19 2017 11:32
hello, I need some help with ramda and typescript
const test: string[] = unnest([['test'], ['test']])
I have the following error in ts
Type 'string[][]' is not assignable to type 'string[]'. Type 'string[]' is not assignable to type 'string'.
Walle Cyril
@GrosSacASac
Dec 19 2017 12:47
Opinion: What do you recommend for static website hosting and dynamic website hosting with node js (separate)
Ændrew Rininsland
@aendrew
Dec 19 2017 13:07
Any suggestions how to debug things written in Ramda? I've written a helper library that has a bug somewhere and I'm having a hard time pinning down which of my functions is even throwing, much less why.
Rolf Strijdhorst
@rolfst
Dec 19 2017 13:07
actually? console.log
or the repl
Ændrew Rininsland
@aendrew
Dec 19 2017 13:13

:worried: So… when I've created a function like:

const getExtIfBlob = R.cond([
  [
    R.and(
      R.compose(R.startsWith('blob:'), R.view(R.lensProp('preview'))),
      R.compose(R.either(R.equals('Object'), R.equals('File')), R.type),
    ),
    R.converge(R.append, [
      R.compose(R.last, getFileExtension, R.prop('name')),
      R.compose(R.of, R.prop('preview')),
    ]),
  ],
  [
    R.T,
    getFileExtension,
  ],
]);

… How would I inject console.log statements into that?

Vesa Karvonen
@polytypic
Dec 19 2017 13:17
R.tap(console.log)
Ændrew Rininsland
@aendrew
Dec 19 2017 13:21

So I'd do something like…

const getExtIfBlob = R.cond([
  [
    R.and(
      R.compose(R.startsWith('blob:'), R.view(R.lensProp('preview'))),
      R.compose(R.either(R.equals('Object'), R.equals('File')), R.type),
    ),
    R.converge(R.append, [
      R.compose(R.last, R.compose(R.tap(console.log('is a blob')), getFileExtension), R.prop('name')),
      R.compose(R.of, R.prop('preview')),
    ]),
  ],
  [
    R.T,
    R.compose(R.tap(console.log('not a blob')), getFileExtension),
  ],
]);

?

Vesa Karvonen
@polytypic
Dec 19 2017 13:25
No, that would execute the console.log calls immediately.

You could create a helper like this:

const show = label => R.tap(data => console.log(label, data))

Then you can R.compose(show('after'), someFunction, show('before')) to see what data flows through.

I would also suggest adding pre/post condition checks to functions.

Claudio Corridore
@ClaudioCorridore
Dec 19 2017 14:40
anyone could help me with my typescript issue?
Ændrew Rininsland
@aendrew
Dec 19 2017 16:46
@polytypic That's super helpful, thank you very much! :D
Brad Compton (he/him)
@Bradcomp
Dec 19 2017 19:19
@ClaudioCorridore I don't think too many people here use ts with Ramda. It may help if you could provide the type signature for unnest that you're using.

For reference, here's the sig in the documentation: Chain c => c (c a) → c a.

That is not able to be represented in ts due to the lack of higher kinded types.

Urban
@UrKr
Dec 19 2017 20:50
Why is the typing of pathOr pathOr<T>(default: T, path: (string | number)[], obj: any): any ?
Why not an additional typevariable for the return value?
Urban
@UrKr
Dec 19 2017 21:14
Doing npm install @types/npm-ramda#dist instead of npm install @types/ramda seems to have 'fixed' it
Lewis
@6ewis
Dec 19 2017 21:16
hi all
why evolve is not working https://goo.gl/NbcnVM
I'm just trying to updated a nested object in an object
Vasili Sviridov
@vsviridov
Dec 19 2017 21:18
values for evolve spec must be functions
Vasili Sviridov
@vsviridov
Dec 19 2017 21:19
what are you trying to do?
Lewis
@6ewis
Dec 19 2017 21:20
just simply updated an nested object field within an object
Vasili Sviridov
@vsviridov
Dec 19 2017 21:20
can you give an example of source and result?
Lewis
@6ewis
Dec 19 2017 21:22
var state = { 
        colors: {
          all: false,
          filteredBy: [
            {
                "id": "1",
                "enable": true
            },
            {
                "id": "591c1e632b185e1add2214d6",
                "enable": true
            },
          ]
    }
}
TO
```
 { 
        colors: {
          all: false,
          filteredBy: [
            {
                "id": "1",
                "enable": false
            },
            {
                "id": "591c1e632b185e1add2214d6",
                "enable": true
            },
          ]
    }
}
Vasili Sviridov
@vsviridov
Dec 19 2017 21:23
so, set enable to false if id===1?
Alec
@alavkx
Dec 19 2017 21:23

@franciscotln

@alavkx filter complement equals is the same as reject equals :-)
https://goo.gl/ydoLBg

Ha! Got hung up on looking for a "does not equal". Nice one

Lewis
@6ewis
Dec 19 2017 21:23
@vsviridov yes
Vasili Sviridov
@vsviridov
Dec 19 2017 21:23
why not map?
Mike Lambert
@lax4mike
Dec 19 2017 21:24
you can use a lens or assocPath
Vasili Sviridov
@vsviridov
Dec 19 2017 21:25
@lax4mike how would you target specific object by its property with a lens?
Mike Lambert
@lax4mike
Dec 19 2017 21:25
R.assocPath(["colors", "filteredBy", 0, "enabled"], false, obj)
or R.set(R.lensPath(["colors", "filteredBy", 0, "enabled"]), false, obj)
Vasili Sviridov
@vsviridov
Dec 19 2017 21:25
but how do you get the 0?
Mike Lambert
@lax4mike
Dec 19 2017 21:25
that can be dynamic if you want
R.assocPath(["colors", "filteredBy", dynamicIndex, "enabled"], false, obj)
Vasili Sviridov
@vsviridov
Dec 19 2017 21:26
so you get the index first...
Mike Lambert
@lax4mike
Dec 19 2017 21:26
perhaps with R.findIndex
Brad Compton (he/him)
@Bradcomp
Dec 19 2017 21:28
@ram-bot
const filteredByLens = lensPath(['colors', 'filteredBy']);

const mapWhen = curry((pred, f, arr) => map(when(pred, f), arr);

const updatefilter = over(filteredByLens, mapWhen(propEq('id', '1'), not))({ 
        colors: {
          all: false,
          filteredBy: [
            {
                "id": "1",
                "enable": true
            },
            {
                "id": "591c1e632b185e1add2214d6",
                "enable": true
            },
          ]
    }
})
ram-bot
@ram-bot
Dec 19 2017 21:28
missing ) after argument list
Brad Compton (he/him)
@Bradcomp
Dec 19 2017 21:29
:(
That's what I meant ;)
Lewis
@6ewis
Dec 19 2017 21:30
function voila() {
      filteredBy = (f) => {
        if (f.id === "1") {
          return R.merge(f, { enable: !f.enable });
        }
        return f;
      };

     const transformations = {
       colors: {
         all: 1,
         filteredBy: R.map(filteredBy)
       }
     }

     return R.evolve(transformations, state)
}
voila()
Brad Compton (he/him)
@Bradcomp
Dec 19 2017 21:30
:+1:
Lewis
@6ewis
Dec 19 2017 21:32
trying to wrap my head around lenspath and mapWhen, and over
which solution is simpler
Mike Lambert
@lax4mike
Dec 19 2017 21:34
when is essentially the if/else in your filteredBy
Lewis
@6ewis
Dec 19 2017 21:37
it's crazy how brad always come with solutions in 10s
thanks @lax4mike @Bradcomp and @vsviridov
can someone explain to me lens or a point me to a good text to wrap my head around it
Lewis
@6ewis
Dec 19 2017 21:44
@vsviridov thanks I'm on it
Alec
@alavkx
Dec 19 2017 21:52
@6ewis swap out assoc('enable', false) in @Bradcomp's solution for evolve({enable: not}) if you'd prefer it to toggle
Lewis
@6ewis
Dec 19 2017 22:13
@alavkx in that case why not use evolve from the get go
Alec
@alavkx
Dec 19 2017 22:24
Hmm, let me see what it would look like. I have a feeling it would be a bit sloppier than @Bradcomp's solution
Alec
@alavkx
Dec 19 2017 22:33
@6ewis you hit the same roadblock as in the other solution. In order to 'toggle', you need to reference the previous value
"assoc" can not be used with a function, only a value
You need a higher order function like evolve in this case. There may be other options I'm unaware of
https://goo.gl/kMhNnT
Brad Compton (he/him)
@Bradcomp
Dec 19 2017 22:53

I try to separate my functions that operate on values from those that operate on structures. So I would do something like this: https://goo.gl/4CN3pa

You could write the toggleEnable function however you want.

I think evolve is probably a little cleaner than using a lens...
Vesa Karvonen
@polytypic
Dec 19 2017 22:54
@6ewis This one is simple with Partial Lenses. There is also quite a bit of documentation that might help you understand optics.
Brad Compton (he/him)
@Bradcomp
Dec 19 2017 22:54
:+1:
The benefit of lenses over evolve or assoc is that you can generate them for whatever structure you have, and then just mix and match with you functions over values.
whereas with evolve you have to specify the shape of the data along with your modification function, if that makes sense
Vasili Sviridov
@vsviridov
Dec 19 2017 22:58
That's pretty cool
Alec
@alavkx
Dec 19 2017 23:04

I try to separate my functions that operate on values from those that operate on structures.

@Bradcomp That's a good principle :)

Vesa Karvonen
@polytypic
Dec 19 2017 23:05
@Bradcomp You might know this already, but Partial Lenses provides "transforms" in addition to optics (isos, lenses, and traversals in PL). Transforms share the same underlying implementation and compose with optics and allow you to do evolve style operations where you can do different things to different parts of the data structure.
Keith Alexander
@kwijibo
Dec 19 2017 23:24
nice
Brad Compton (he/him)
@Bradcomp
Dec 19 2017 23:29
Cool!
I have been meaning to check out the whole calmm system, but it's been a while since I've done any new personal projects