Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

We already have .flatMap & .flatMapError, adding .flatMapEnd seems like a logical continuation. It will be a more powerful alternative to .beforeEnd, which allows only to insert a value before end.

Inserting a value before end

// Before
foo.beforeEnd(() => 1)

// After
foo.flatMapEnd(() => Kefir.constant(1))

Inserting a error before end

// Before 
// (will work only if foo does't contain other values, 
// otherwise it will be even trickier)
foo.beforeEnd(() => 1).flatMap(Kefir.constantError)

// After
foo.flatMapEnd(() => Kefir.constantError(1))

Inserting multiple values

// Before 
// (Will work only if foo does't contain other values, 
// otherwise it will be even trickier)
foo.beforeEnd(() => 1).flatMap(() => Kefir.sequentially(1000, [1, 2, 3]))

// After
foo.flatMapEnd(() => Kefir.sequentially(1000, [1, 2, 3]))

Ignoring the end

// Before

// After
// (Suppose we'll have Kefir.neverEnd() 
// similar to Kefir.never() but that also doesn't end)

The 1 & 4 examples aren’t very convincing as current alternative is easier, but I still include them to better illustrate potential of .flatMapEnd.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

rpominovcommented, Jul 10, 2016

Maybe something like this:

let bind = () => bindEvents(events, el)

  .map(render$ => render$.ignoreValues().ignoreErrors().beforeEnd(bind))
mAAdhaTTahcommented, Jul 9, 2016

Here’s how I ended up handling it:

function makeEventSwapper(events : EventsConfig, el : HTMLElement) {
    let sub : Subscription = { closed: true };
    // bindEvents returns a stream of DOM events.
    let bind = () => bindEvents(events, el) : Kefir.Observable;

    return (emitter, event) => {
        if (event.type === 'value') {
            if (!sub.closed) {

            const render$ : Kefir.Observable = event.value;
            sub = render$.observe({ complete: () => });

    .withEventHandler(makeEventSwapper(events, el))

Can you see a better way?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Java 8 Streams: Definitive Guide to flatMap() - Stack Abuse
The flatMap() operation returns a cummulative stream, generated from multiple other streams. The elements of the stream are created by applying ...
Read more >
Project Reactor: map() vs flatMap() - Baeldung
This tutorial introduces the map and flatMap operators in Project Reactor. They're defined in the Mono and Flux classes to transform items ...
Read more >
Why doesn't this map() or flatMap() finish the pipeline even ...
you get a Mono<Boolean> because ArrayList#add() returns a boolean. If you don't need the transformation, you can call doOnNext() . List<String> tokens =...
Read more >
Stream flatMap() in Java with examples - GeeksforGeeks
Stream flatMap(Function mapper) returns a stream consisting of the results of replacing each element of this stream with the contents of a ...
Read more >
Array.prototype.flatMap() - JavaScript - MDN Web Docs
The flatMap() method returns a new array formed by applying a given callback function to each element of the array, and then flattening...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found