@phryxia/oof
TypeScript icon, indicating that this package has built-in type declarations

1.0.7 • Public • Published

oof!

oof is a tiny TypeScript library for functional programming utilities with type safety. When learning functional paradigm with JavaScript, you may feel some despair of typing pipe (or go) correctly.

API

// you only type once
const foo = oof((x: string) => x.length)
  .compose(num => num === 42)
  .compose(isTruthUnveiled => isTruthUnveiled ? () => console.log("I'm die. Thank you forever.") : () => {})

// you can call this directly
foo() // foo(x: string): () => void

// want to proceed more?
const bar = foo.compose()

Why?

// You're currently writing a nice composed function...
pipe(
  (value: string) => returnsSomeNiceComplexType(),
  // Parameter 'iWantNoImplicitAnyBeTrue' implicitly has an 'any' type (7006)
  (iWantNoImplicitAnyBeTrue) => butYouCantBecauseAboveTypeIsHell(),
)

// This is also verbose
// since most of the time you start with inner things
const result = pipe<[Do, I, Have, To, Declare, These, Always, QuestionMark]>(
  what,
  if,
  you,
  add,
  other,
  functions,
  somewhere,
  between,
  these // type error: Expected 8 arguments, but got 9 (2554)
)

// of course, this anyscript often ends up with 
// "Uncaught ReferenceError: peace is not defined"
result.peace()

Package Sidebar

Install

npm i @phryxia/oof

Weekly Downloads

0

Version

1.0.7

License

MIT

Unpacked Size

4.1 kB

Total Files

12

Last publish

Collaborators

  • phryxia