Skip to content

2.1.0

Compare
Choose a tag to compare
@musicq musicq released this 18 May 16:56
· 37 commits to main since this release

New Features

  • Introducing the toWrap operator for users of rxjs.

Now if you are using rxjs and want to use wrap function to wrap the result of a pipe into Result type, you can directly use toWrap operator.

import { from, map } from 'rxjs'
import { toWrap } from 'unwrapit'

from([1, 2, 3])
  .pipe(
    map((x) => {
      if (x % 2 === 0) throw new Error(`num ${x} is even.`)
      return x
    }),
    toWrap()
  )
  .subscribe((x) => {
    if (!x.ok) return console.error(x.error) // Error: num 2 is even.
    console.log(x.value)
  })

Normally, it is recommended to place the toWrap operator as the last operator in your pipe function to ensure that it can catch all errors. However, you can also position it based on your specific requirements.