Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split a flux into two fluxes - head and tail

I want to split a flux into two fluxes where the first one has the first item of the original flux and the second one will takes the rest of items.

After applying a custom transformation myLogic on each flux I want to combine them into one flux preserving the order of the original flux.

Example:

S: student
S': student after applying myLogic

Emitted flux: s1 -> s2 -> s3 -> s4
The first splited flux: s1' => myLogic
The second splited flux: s2' -> s3' -> s4' => myLogic
The combined flux: s1' -> s2' -> s3' -> s4'

like image 358
suliman Avatar asked Nov 04 '19 15:11

suliman


People also ask

What is flux-split-based FDM?

Such a flux-split-based FDM consists of two steps. In the first step, flux vector splitting (FVS) methods, such as the Steger–Warming FVS [16] and van Leer FVS [17], [18], are frequently used to split the flux vector into positive and negative flux vectors.

What is heat flux and its types?

We will further study the types of Heat Flux and the heat flux formula. What is Heat Flux? Heat flux also named as thermal flux, is referred to as heat flux density, heat-flow density is a flow of energy per unit of area per unit of time.

How to split the path name into head and tail?

os.path.split () method in Python is used to Split the path name into a pair head and tail. Here, tail is the last path name component and head is everything leading up to that. For example consider the following path name: path name = '/home/User/Desktop/file.txt'.

What is the heat flux of a chip?

where Q is the heat transfer rate, A is the cross-sectional through which the heat transfer is taking place, is the heat flux. Heat dissipated by each chip = 0.12 W


1 Answers

It is enough to use standard Flux methods take and skip to seprate head and tail elements. Calling cache before that is also useful to avoid subscription duplication.

class Util {

  static <T, V> Flux<V> dualTransform(
    Flux<T> originalFlux,
    int cutpointIndex,
    Function<T, V> transformHead,
    Function<T, V> transformTail
  ) {
    var cached = originalFlux.cache();
    var head = cached.take(cutpointIndex).map(transformHead);
    var tail = cached.skip(cutpointIndex).map(transformTail);

    return Flux.concat(head, tail);
  }

  static void test() {
    var sample = Flux.just("a", "b", "c", "d");

    var result = dualTransform(
                   sample,
                   1, 
                   x -> "{" + x.toUpperCase() + "}", 
                   x -> "(" + x + ")"
                 );

    result.doOnNext(System.out::print).subscribe();

    // prints: {A}(b)(c)(d)
  }
}
like image 139
diziaq Avatar answered Sep 18 '22 15:09

diziaq