liveBook · Manning

MonoTypeOperatorFunction

As explained in Modern Angular

MonoTypeOperatorFunction is an RxJS operator function type whose source and result observables have the same value type.

MonoTypeOperatorFunction is an RxJS operator function type for operators that preserve the source observable’s value type. Unlike OperatorFunction, it accepts one type parameter because source and result types remain the same. section 5.4.3

Use MonoTypeOperatorFunction when an operator observes, filters, or otherwise processes emissions without changing their type:

  • filter restricts emissions without changing their value type. section 5.4.3
  • A logging operator can perform a tap side effect while leaving the stream unchanged. section 5.4.3
  • The independent pipe function packages reusable operator logic and returns a type-preserving operator. section 5.4.3

Typed custom logging operator

function log<T>(message: string = ''): MonoTypeOperatorFunction<T> { return pipe(tap(item => console.log(`${message ? message + ': ' : ''}${item}`))); } section 5.4.3

Listing 5.12 Using RxJS built-in tools to create a custom operator
function log<T>(
  message: string = ''
): MonoTypeOperatorFunction<T> {  #1
  return pipe(  #2
    tap(item => console.log(`${message ? message + ': ' :  ''}${item}`)),
  );
}

Browse the compact implementation showing how MonoTypeOperatorFunction and pipe replace custom operator boilerplate. section 5.4.3

How Modern Angular covers it

How deep it goes
Explains the type distinction and demonstrates logging, filtering, piping, and permission-based operators without detailing RxJS internals.
Examples
Uses configurable logging, permission filtering, an Angular HTTP interceptor, and marble diagrams for filter and permission behavior.
What it assumes
Assumes familiarity with observables and OperatorFunction while contrasting changed-type operators such as map with type-preserving operators.
What you can do after
Build custom type-preserving RxJS operators with pipe, tap, filtering, and optional Angular dependency injection.
How it connects
Connects OperatorFunction with Observable, filter, tap, map, pipe, dependency injection, and Angular interceptors.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern Angular. The section links point to the parts of the book it draws on.