0.0.2 • Published 5 years ago

@sullux/fp-light-resolve v0.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

home

fp-light-resolve

npm i @sullux/fp-light-resolve
source
test

Deeply resolves all functions and promises.

resolve

resolve(target, input)

Resolution involves passing the input to the target (if a function) or to any function found on the target (if an object or iterable). If any literal or resolved value anywhere in the result is a thenable, or if the input is a thennable, the return value of resolve is a promise; otherwise, the return value is the target after having been fully-resolved with the input.

resolve('foo', 42) // 'foo'
resolve(x => x + 1, 42) // 43
resolve(['foo', x => x + 1], 42) // ['foo', 43]
resolve({ foo: 'bar', baz: x => x + 1 }, 42) // { foo: 'bar', baz: 43 }

resolve(x => x + 1, Promise.resolve(42))
  // promise -> 42

resolve({ foo: 'bar', baz: x => Promise.resolve(x + 1) }, 42)
  // promise -> { foo: 'bar', baz: 43 }

resolve(
  {
    foo: Promise.resolve('bar'),
    baz: Promise.resolve(x => Promise.resolve(x + 1))
  },
  Promise.resolve(42)
)
  // promise -> { foo: 'bar', baz: 43 }