From Discord: Issue with Type Inference in Effect.liftPredicate Function
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:
- Data-last Function Usage:
Effect.liftPredicateis expected to be used within apipe, impacting type inference. - Inconsistency in Behavior:
Effect.liftPredicatebehaves differently thanOption.liftPredicate, which causes confusion. - Semantics of Lifting: The inclusion of immediate application in
Effect.liftPredicateseems unexpected compared to other similar functions. - Possible Improvement: There may be a need to align
Effect.liftPredicatewith functions likeOption.liftPredicatefor consistent behavior. - 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