npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

swisslist

v0.0.4

Published

A functional, immutable list implementation with a rich set of methods for manipulating collections.

Readme

SwissList

A functional, immutable list implementation with a rich set of methods for manipulating collections in TypeScript.

Features

  • 🛡️ Type Safety: Fully typed with TypeScript
  • 🔄 Immutable: All operations return new instances
  • 🧩 Functional: Rich set of functional programming methods
  • 🚀 Performance: Optimized for common operations
  • 📦 Zero Dependencies: Lightweight and self-contained

Installation

npm install swisslist

Usage

Basic Usage

import { List } from 'swisslist'

// Create a new list
const list = List.of(1, 2, 3, 4, 5)

// Transform elements
const doubled = list.map((x) => x * 2)

// Filter elements
const evenNumbers = list.filter((x) => x % 2 === 0)

// Reduce elements
const sum = list.reduce((acc, curr) => acc + curr, 0)

// Chain operations
const result = list
  .filter((x) => x > 2)
  .map((x) => x * 3)
  .take(2)

React Example: Todo List

Here's how you can use SwissList to manage a todo list state in React:

import { useState } from 'react'
import { List } from 'swisslist'

interface Todo {
  id: number
  text: string
  completed: boolean
}

function TodoList() {
  const [todos, setTodos] = useState(List.empty<Todo>())

  // Add a new todo
  const addTodo = (text: string) => {
    setTodos((current) =>
      current.append({
        id: Date.now(),
        text,
        completed: false,
      }),
    )
  }

  // Toggle todo completion using updateWhere
  const toggleTodo = (id: number) => {
    setTodos((current) =>
      current.updateWhere(
        (todo) => todo.id === id,
        (todo) => ({ ...todo, completed: !todo.completed }),
      ),
    )
  }

  // Remove a todo using the index from map
  const removeTodo = (index: number) => {
    setTodos((current) => current.removeAt(index))
  }

  // Move a todo up or down in the list
  const moveTodo = (index: number, direction: 'up' | 'down') => {
    setTodos((current) => {
      const newIndex = direction === 'up' ? index - 1 : index + 1
      return current.move(index, newIndex)
    })
  }

  // Get active todos
  const activeTodos = todos.filter((todo) => !todo.completed)

  return (
    <div>
      <input
        type="text"
        onKeyDown={(e) => {
          if (e.key === 'Enter') {
            addTodo(e.currentTarget.value)
            e.currentTarget.value = ''
          }
        }}
      />
      <ul>
        {todos.map((todo, index) => (
          <li key={todo.id}>
            <input
              type="checkbox"
              checked={todo.completed}
              onChange={() => toggleTodo(todo.id)}
            />
            <span
              style={{
                textDecoration: todo.completed ? 'line-through' : 'none',
              }}
            >
              {todo.text}
            </span>
            <button onClick={() => removeTodo(index)}>Delete</button>
            <button
              onClick={() => moveTodo(index, 'up')}
              disabled={todos.isFirst(index)}
            >
              ↑
            </button>
            <button
              onClick={() => moveTodo(index, 'down')}
              disabled={todos.isLast(index)}
            >
              ↓
            </button>
          </li>
        ))}
      </ul>
      <p>Active todos: {activeTodos.size}</p>
    </div>
  )
}

Mathematical Operations

SwissList provides a rich set of mathematical operations that work with any type of data through selector functions:

import { List } from 'swisslist'

// Example: Working with a list of products
interface Product {
  name: string
  price: number
  quantity: number
}

const products = List.of<Product>(
  { name: 'Apple', price: 1.5, quantity: 10 },
  { name: 'Banana', price: 0.5, quantity: 20 },
  { name: 'Orange', price: 1, quantity: 15 },
  { name: 'Mango', price: 2, quantity: 8 },
)

// Calculate total value of inventory
const totalValue = products.sumBy((p) => p.price * p.quantity)
console.log(`Total inventory value: $${totalValue}`) // $45.5

// Find average price
const avgPrice = products.averageBy((p) => p.price)
console.log(`Average price: $${avgPrice}`) // $1.25

// Find median quantity
const medianQuantity = products.medianBy((p) => p.quantity)
console.log(`Median quantity: ${medianQuantity}`) // 12.5

// Calculate price range
const priceRange = products.rangeBy((p) => p.price)
console.log(`Price range: $${priceRange}`) // $1.5

// Find most common quantity
const modeQuantity = products.modeBy((p) => p.quantity)
console.log(`Most common quantity: ${modeQuantity}`) // 10

// Calculate geometric mean of quantities
const geoMeanQuantity = products.geometricMeanBy((p) => p.quantity)
console.log(`Geometric mean of quantities: ${geoMeanQuantity}`) // 12.649110640673518

// Calculate standard deviation of prices
const priceStdDev = products.standardDeviationBy((p) => p.price)
console.log(`Price standard deviation: $${priceStdDev}`) // $0.6454972243679028

// Example: Working with student grades
interface Student {
  name: string
  grades: number[]
}

const students = List.of<Student>(
  { name: 'Alice', grades: [85, 90, 88] },
  { name: 'Bob', grades: [92, 88, 95] },
  { name: 'Charlie', grades: [78, 85, 80] },
)

// Calculate average grade for each student
const studentAverages = students.map((student) => ({
  name: student.name,
  average: List.from(student.grades).averageBy((g) => g),
}))

console.log('Student averages:', studentAverages)
// [
//   { name: 'Alice', average: 87.66666666666667 },
//   { name: 'Bob', average: 91.66666666666667 },
//   { name: 'Charlie', average: 81 }
// ]

// Find the student with the highest average
const bestStudent = studentAverages.reduce(
  (best, current) => (current.average > best.average ? current : best),
  studentAverages[0],
)
console.log(`Best performing student: ${bestStudent.name}`) // Bob

// Example: Chaining mathematical operations
const salesData = List.of(
  { product: 'A', sales: [100, 120, 90, 110] },
  { product: 'B', sales: [80, 85, 95, 100] },
  { product: 'C', sales: [150, 140, 160, 155] },
)

// Calculate statistics for products with average sales above 100
const highPerformingProducts = salesData
  .map((data) => ({
    product: data.product,
    average: List.from(data.sales).averageBy((s) => s),
    stdDev: List.from(data.sales).standardDeviationBy((s) => s),
  }))
  .filter((data) => data.average > 100)
  .sort((a, b) => b.average - a.average)

console.log('High performing products:', highPerformingProducts)
// [
//   { product: 'C', average: 151.25, stdDev: 8.539125638299666 },
//   { product: 'A', average: 105, stdDev: 12.909944487358056 }
// ]

These mathematical operations are particularly useful for:

  • Data analysis and statistics
  • Financial calculations
  • Grade management systems
  • Inventory management
  • Performance metrics
  • Scientific computations