Giter Site home page Giter Site logo

Value first pipe about ts-belt HOT 4 CLOSED

mobily avatar mobily commented on July 17, 2024 1
Value first pipe

from ts-belt.

Comments (4)

mobily avatar mobily commented on July 17, 2024 1

@flauwekeul added and published in v3.6.0 πŸš€

from ts-belt.

mobily avatar mobily commented on July 17, 2024

Unless I'm missing something

no, you’re actually not missing anything :)

I think this is very clean.

I take your point and fully agree this is a very clean solution, but on the other hand most of the time it requires defining types manually, which is not developer-friendly and was much problematic in Ramda (if you use Ramda in TS), and basically I wanted to avoid this, for instance:

type SomeType1 = {
  readonly prop: string
}

const someFn: (arg: SomeType1) => string = createPipe(D.getUnsafe('prop'), S.toUpperCase)

someFn(value)

with the current implementation, you only need to define a type to the provided argument and a result type is correctly inferred:

type SomeType1 = {
  readonly prop: string
}

const someFn = (value: SomeType1) => pipe(value, D.getUnsafe('prop'), S.toUpperCase)

someFn(value)

I consider adding pipe that returns a new function and accepts a single argument but still, due to TS limitations, most of the time developers will have to use it like the following to get types correctly inferred:

const value =  pipe(
  ['hello', 'world'], 
  A.map(createPipe(S.remove('o'), S.toUpperCase)),
) // β†’ ['HELL', 'WRLD']

from ts-belt.

flauwekeul avatar flauwekeul commented on July 17, 2024

Thanks for explaining. I didn't take into account that TS is the limiting factor here. Also, I see that fp-ts' pipe has the same signature, probably for the same reason. However, fp-ts also has the flow util. I haven't used it yet, but maybe they figured out a way to make it infer types without too much hassle.

from ts-belt.

mobily avatar mobily commented on July 17, 2024

thanks for sharing the link! ❀️ good news, the initial implementation of flow in ts-belt looks really promising, and I think it will be included in the next version

from ts-belt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.