Katxupa
  • 👋Welcome to Katxupa Extension Library
  • Why Katxupa?
    • 🍻What makes Katxupa special?
    • ✨Key Features
  • Get a taste of Katxupa
    • 🍲Installation
    • 🍜Usage
      • 🍻Scope Functions
        • Function Selection
        • Distinctions
        • Functions
          • letIt
          • withIt
          • runIt
          • applyIt
          • alsoIt
          • takeIf and takeUnless
      • 😎Null Safety
        • TypeScript Null-Safety
        • Optional Chaining for JavaScript
      • ⏰Duration
      • ➖Reducer
      • 📏Range
      • 🏃‍♂️Result
      • 🤼Either
      • 🟰Compare
      • ⚔️Global Utility Functions
    • 🤌Dip Dive
      • Optional
      • Range
      • Duration
      • Reducer
      • Collections
        • Array
        • Set
  • 🙏Support
    • Source Code
    • ESLint Config
    • TypeScript Docs
    • Manuel Santos Linkedin
Powered by GitBook
On this page
  1. Get a taste of Katxupa
  2. Usage

Range

PreviousReducerNextResult

Last updated 1 year ago

The Range class provides utility methods for working with numeric ranges.

// Example 1: range with step
rangeTo(0,10,3)
    .forEach(it => console.log(`Index: ${it}`));
// Output:
//    Index: 0
//    Index: 3
//    Index: 6
//    Index: 9
// Example 2: Creating a Numeric Range
const numericRange = Range.rangeTo(1, 5, 2);
console.log(numericRange); 
// Output: [1, 3, 5]
// Example 3: Creating a Numeric Range (Exclusive)
const numericRangeAlias = rangeUntil(1, 5, 2);
console.log(numericRangeAlias); 
// Output: [1, 3, 5]
// Example 4: Checking if a Value is in Range
const isInRange = Range.inRange(3, 1, 5);
console.log(isInRange); 
// Output: true
// Example 5: Range with chaining Operations 
rangeTo(1, 5, 2)
    .runIt(function () {
        console.log(`multiplying the following range of numbers: ${this}`);
        this.map(it => it * 2)
            .forEach(it => console.log(it));
    });
// Output:
//    multiplying the following range of numbers: 1,3,5
//    2
//    6
//    10

🍜
📏
Range