effect icon indicating copy to clipboard operation
effect copied to clipboard

From Discord: Issue with Type Inference in Effect.liftPredicate Function

Open effect-bot opened this issue 8 months ago • 0 comments

Summary

The conversation revolves around an issue with type inference in the Effect.liftPredicate function from the Effect TypeScript library. The user, ttncrch, points out that the predicate's type is not inferred correctly when using Effect.liftPredicate, unlike their experience with Option.liftPredicate, which works as expected. Khraks_mamtsov explains that the library assumes data-last functions will be used in a pipe and acknowledges that a different behavior might be expected for this use case.

Khraks_mamtsov reflects on the semantics of predicate lifting, noting it is strange that Effect.liftPredicate includes the ability to apply immediately. They find that Either|Effect.liftPredicate should arguably behave like Option|Array.liftPredicate, which creates reusable functions. They also reference a comment in the source code that suggests a certain intended behavior, mentioning a deliberate avoidance of using the NoInfer pattern.

Key Takeaways:

  1. Data-last Function Usage: Effect.liftPredicate is expected to be used within a pipe, impacting type inference.
  2. Inconsistency in Behavior: Effect.liftPredicate behaves differently than Option.liftPredicate, which causes confusion.
  3. Semantics of Lifting: The inclusion of immediate application in Effect.liftPredicate seems unexpected compared to other similar functions.
  4. Possible Improvement: There may be a need to align Effect.liftPredicate with functions like Option.liftPredicate for consistent behavior.
  5. Source Code Insight: The mention of avoiding the NoInfer pattern suggests a deliberate design choice in the library's implementation.

Discord thread

https://discord.com/channels/795981131316985866/1356920778075144312

effect-bot avatar Apr 02 '25 11:04 effect-bot