functype 0.8.80 → 0.8.82

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -133,9 +133,9 @@ const withFive = numbers.add(5) // List([1, 2, 3, 4, 5])
133
133
  const without3 = numbers.remove(3) // List([1, 2, 4])
134
134
 
135
135
  // Universal container operations
136
- const hasEven = numbers.exists(x => x % 2 === 0) // true
137
- const firstEven = numbers.find(x => x % 2 === 0) // Some(2)
138
- const evenCount = numbers.count(x => x % 2 === 0) // 2
136
+ const hasEven = numbers.exists((x) => x % 2 === 0) // true
137
+ const firstEven = numbers.find((x) => x % 2 === 0) // Some(2)
138
+ const evenCount = numbers.count((x) => x % 2 === 0) // 2
139
139
  ```
140
140
 
141
141
  ### Try
@@ -179,13 +179,13 @@ const value1 = expensive.get() // Logs "Computing...", returns number
179
179
  const value2 = expensive.get() // Returns same number, no log
180
180
 
181
181
  // Transform lazy values
182
- const doubled = expensive.map(x => x * 2)
183
- const formatted = doubled.map(x => `Value: ${x}`)
182
+ const doubled = expensive.map((x) => x * 2)
183
+ const formatted = doubled.map((x) => `Value: ${x}`)
184
184
 
185
185
  // Chain computations
186
186
  const result = Lazy(() => 10)
187
- .flatMap(x => Lazy(() => x + 5))
188
- .map(x => x * 2)
187
+ .flatMap((x) => Lazy(() => x + 5))
188
+ .map((x) => x * 2)
189
189
  .get() // 30
190
190
  ```
191
191
 
@@ -275,10 +275,10 @@ import { Cond } from "functype"
275
275
 
276
276
  // Replace if-else chains with Cond
277
277
  const grade = Cond<number, string>()
278
- .case(score => score >= 90, "A")
279
- .case(score => score >= 80, "B")
280
- .case(score => score >= 70, "C")
281
- .case(score => score >= 60, "D")
278
+ .case((score) => score >= 90, "A")
279
+ .case((score) => score >= 80, "B")
280
+ .case((score) => score >= 70, "C")
281
+ .case((score) => score >= 60, "D")
282
282
  .default("F")
283
283
 
284
284
  console.log(grade(85)) // "B"
@@ -287,16 +287,16 @@ console.log(grade(55)) // "F"
287
287
  // With transformation
288
288
  const discount = Cond<number, number>()
289
289
  .case(
290
- qty => qty >= 100,
291
- qty => qty * 0.20 // 20% off for 100+
290
+ (qty) => qty >= 100,
291
+ (qty) => qty * 0.2, // 20% off for 100+
292
292
  )
293
293
  .case(
294
- qty => qty >= 50,
295
- qty => qty * 0.10 // 10% off for 50+
294
+ (qty) => qty >= 50,
295
+ (qty) => qty * 0.1, // 10% off for 50+
296
296
  )
297
297
  .case(
298
- qty => qty >= 10,
299
- qty => qty * 0.05 // 5% off for 10+
298
+ (qty) => qty >= 10,
299
+ (qty) => qty * 0.05, // 5% off for 10+
300
300
  )
301
301
  .default(0)
302
302
 
@@ -323,12 +323,12 @@ console.log(statusMessage("approved")) // "Your request has been approved!"
323
323
  // Match with predicates
324
324
  const numberType = Match<number, string>()
325
325
  .case(0, "zero")
326
- .case(n => n > 0, "positive")
327
- .case(n => n < 0, "negative")
326
+ .case((n) => n > 0, "positive")
327
+ .case((n) => n < 0, "negative")
328
328
  .exhaustive()
329
329
 
330
- console.log(numberType(42)) // "positive"
331
- console.log(numberType(-5)) // "negative"
330
+ console.log(numberType(42)) // "positive"
331
+ console.log(numberType(-5)) // "negative"
332
332
  ```
333
333
 
334
334
  ## Fold
@@ -464,32 +464,28 @@ All data structures implement the `Functype` hierarchy:
464
464
 
465
465
  ```typescript
466
466
  // Base interface for all data structures
467
- interface FunctypeBase<A, Tag> extends
468
- AsyncMonad<A>,
469
- Traversable<A>,
470
- Serializable<A>,
471
- Foldable<A>,
472
- Typeable<Tag>,
473
- ContainerOps<A> {
467
+ interface FunctypeBase<A, Tag>
468
+ extends AsyncMonad<A>,
469
+ Traversable<A>,
470
+ Serializable<A>,
471
+ Foldable<A>,
472
+ Typeable<Tag>,
473
+ ContainerOps<A> {
474
474
  readonly _tag: Tag
475
475
  }
476
476
 
477
477
  // For single-value containers (Option, Either, Try)
478
- interface Functype<A, Tag> extends
479
- FunctypeBase<A, Tag>,
480
- Extractable<A>,
481
- Pipe<A>,
482
- Matchable<A, Tag> {
478
+ interface Functype<A, Tag> extends FunctypeBase<A, Tag>, Extractable<A>, Pipe<A>, Matchable<A, Tag> {
483
479
  toValue(): { _tag: Tag; value: A }
484
480
  }
485
481
 
486
482
  // For collections (List, Set, Map)
487
- interface FunctypeCollection<A, Tag> extends
488
- FunctypeBase<A, Tag>,
489
- Iterable<A>,
490
- Pipe<A[]>,
491
- Collection<A>,
492
- CollectionOps<A, FunctypeCollection<A, Tag>> {
483
+ interface FunctypeCollection<A, Tag>
484
+ extends FunctypeBase<A, Tag>,
485
+ Iterable<A>,
486
+ Pipe<A[]>,
487
+ Collection<A>,
488
+ CollectionOps<A, FunctypeCollection<A, Tag>> {
493
489
  toValue(): { _tag: Tag; value: A[] }
494
490
  // Collections work with Iterable instead of Monad
495
491
  flatMap<B>(f: (value: A) => Iterable<B>): FunctypeCollection<B, Tag>
@@ -507,17 +503,17 @@ const opt = Option(42)
507
503
  const list = List([1, 2, 3, 4, 5])
508
504
 
509
505
  // Universal operations work on both single-value and collections
510
- opt.count(x => x > 40) // 1
511
- list.count(x => x > 3) // 2
506
+ opt.count((x) => x > 40) // 1
507
+ list.count((x) => x > 3) // 2
512
508
 
513
- opt.find(x => x > 40) // Some(42)
514
- list.find(x => x > 3) // Some(4)
509
+ opt.find((x) => x > 40) // Some(42)
510
+ list.find((x) => x > 3) // Some(4)
515
511
 
516
- opt.exists(x => x === 42) // true
517
- list.exists(x => x === 3) // true
512
+ opt.exists((x) => x === 42) // true
513
+ list.exists((x) => x === 3) // true
518
514
 
519
- opt.forEach(console.log) // Logs: 42
520
- list.forEach(console.log) // Logs: 1, 2, 3, 4, 5
515
+ opt.forEach(console.log) // Logs: 42
516
+ list.forEach(console.log) // Logs: 1, 2, 3, 4, 5
521
517
  ```
522
518
 
523
519
  ## Type Safety