Skip to content

PuraPure FP for TypeScript

Returns native JavaScript types. Immutability faster than mutation. Zero learning curve.

Pura Logo

Quick Example ​

typescript
import { produce } from '@sylphx/pura'

// Returns real Array - use it anywhere!
const state = [1, 2, 3]
const next = produce(state, draft => {
  draft.push(4)
  draft[0] = 999
})

// next is a real Array
next[0]              // ✅ works - it's a real Array
next instanceof Array // ✅ true
await api.send(next)  // ✅ works with any library

// Objects - returns real Object
const user = { name: 'John', age: 30 }
const updated = produce(user, draft => {
  draft.age = 31
})

// Maps & Sets - returns real Map/Set
const map = new Map([['a', 1]])
const newMap = produce(map, draft => {
  draft.set('b', 2)
})
newMap.get('b')      // ✅ works - it's a real Map

Why Pura? ​

vs Immer ​

1.06-105x faster across all scenarios. Structural sharing for arrays/maps/sets (Immer only does objects).

vs Manual Immutability ​

O(log n) vs O(n). Updating element 500 in a 10K array:

  • Manual: Copy entire array (10,000 elements)
  • Pura: Update path to node (~4 nodes)

vs Immutable.js ​

Returns native types (Immutable.js uses custom List/Map wrappers). Zero learning curve. Use result[0] not result.get(0). Works with any library expecting native types.

Performance ​

ScenarioImmerPuraSpeedup
Sets (1K)2.31K ops/s243K ops/s105x faster 🚀
Maps (1K)2.08K ops/s25.1K ops/s12x faster 🚀
Objects (Deep)681K ops/s1.70M ops/s2.5x faster ✅
Arrays (100)0.87M ops/s4.63M ops/s5.3x faster ✅

Installation ​

bash
npm install @sylphx/pura
# or
bun add @sylphx/pura
# or
pnpm add @sylphx/pura

Learn More ​

Released under the MIT License.