Skip to content

Add toMapNotNull operator and fix mapNotNull to filter undefined#6

Merged
iliagon merged 1 commit intomasterfrom
toMapNotNull
Nov 21, 2025
Merged

Add toMapNotNull operator and fix mapNotNull to filter undefined#6
iliagon merged 1 commit intomasterfrom
toMapNotNull

Conversation

@iliagon
Copy link

@iliagon iliagon commented Nov 21, 2025

Summary

This PR adds a new toMapNotNull operator and fixes mapNotNull to filter out both null and undefined values.

Changes

New Feature: toMapNotNull

  • Added toMapNotNull operator for both sync and async sequences
  • Filters out key-value pairs where either the key or value is null or undefined
  • Returns Map<NonNullable<K>, NonNullable<V>> for proper type safety
  • Supports optional map parameter to append to existing map

Fix: mapNotNull

  • Updated mapNotNull to filter out both null and undefined values (previously only filtered null)
  • Updated return type to Sequence<NonNullable<R>> / AsyncSequence<NonNullable<R>> for better type safety
  • Updated documentation to reflect the change

Example Usage

// toMapNotNull example
const map = asSequence([["a", 1], ["b", null], ["c", 2]])
    .toMapNotNull(); // Returns Map with only ["a", 1] and ["c", 2]

// mapNotNull example (now filters undefined too)
const result = sequenceOf(1, 2, 3)
    .mapNotNull(x => x === 2 ? undefined : x)
    .toArray(); // Returns [1, 3]

@iliagon iliagon merged commit ee94413 into master Nov 21, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant