caderek / arrows

Monorepo for functional JS/TS modules
https://caderek.github.io/arrows/
ISC License
192 stars 3 forks source link

Improvements for compose #5

Open reggi opened 5 years ago

reggi commented 5 years ago

Cool library! I've been hunting / trying to make a good compositional library with typescript support.

In my initial test here:

import { compose } from '@arrows/composition'

const addPrefixes = compose(
  (text: string) => `prefix1-${text}`,
  (text: string) => 3,
  (text: string) => `prefix2-${text}`,
)

addPrefixes('arrows') // -> "prefix1-prefix2-arrows"

Here are some thoughts on how to improve typing:

  1. The parameter type of addPrefixes should be string, because it's the parameter of the first function in compose.
  2. You can see above I have the 2nd function which returns 3 and the 4th which takes a string and that shouldn't be allowed.
caderek commented 5 years ago

Thank you, I will look into that.

ivklgn commented 2 years ago

@caderek "better late than never"

if this changes ok - i can fix pipe function next