mostjs / core

Most.js core event stream
http://mostcore.rtfd.io
MIT License
402 stars 36 forks source link

adds 'core/last' emitting the last event. Useful for reduce/fold too. #673

Closed semmel closed 6 months ago

semmel commented 7 months ago

I sometimes need the last value in a stream or reduce it to the last value of scan

I could not find a way to do that with the existing API.

What do you think?

Also adds (helper function) prelude/flow to support function pipelines (in tests)

semmel commented 7 months ago

I guess, Circle CI fails because one needs to npm install --legacy-peer-deps to install the project. npm install no longer works for me (npm v9.8).

TylorS commented 7 months ago

We'll have to look into updating the build (hasn't been a need for a long time), but for this operator specifically, there's already a 3rd party library for this -

https://github.com/mostjs-community/last

semmel commented 7 months ago

We'll have to look into updating the build (hasn't been a need for a long time),

For the time being one could mention npm install --legacy-peer-deps in the Readme perhaps

but for this operator specifically, there's already a 3rd party library for this -

https://github.com/mostjs-community/last

That is awesome, but at the same time so sad that it seems I wasted all the time for this PR 😭

Nevermind, I know now about the implementation. That enables me to attempt Fantasy-Land support. That's a whole other story, but I hate to repeat myself in each file's imports:

import {map , chain} from 'ramda'
import {map as map_o, chain as chain_o} from '@most/core'
TylorS commented 7 months ago

We do really appreciate the effort, and apologize if it feels like a waste of your time. If you'd we so kind to separate the CI fixes, I'd most graciously accept those.

If you're looking for method extensions to Stream, you might find this useful for inspiration at least https://github.com/mostjs/x-fluent. We've avoided fluent APIs in core because they can't be removed during tree-shaking, but they definitely are convenient

briancavalier commented 6 months ago

Hi @semmel. I'll echo @TylorS's apology for the effort you put into your last implementation. Thanks for letting us know about --legacy-peer-deps, and for attempting FL support. I'll take a look at https://github.com/mostjs/core/pull/675.

That's a whole other story, but I hate to repeat myself in each file's imports

Using import * as M from '@most/core' is another option, if you don't mind namespace-style import.