Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Operator <- as Syntax Sugar for yield * #1696

Open
HerringtonDarkholme opened this issue Feb 12, 2025 · 0 comments
Open

[Feature Request] Operator <- as Syntax Sugar for yield * #1696

HerringtonDarkholme opened this issue Feb 12, 2025 · 0 comments
Labels
proposal Proposal or discussion about a significant language feature

Comments

@HerringtonDarkholme
Copy link

Hi Civet Team,

Thank you for your continuous work in enhancing Civet. I'd like to propose a new feature to add the operator <- as syntax sugar for yield *. This feature aims to improve code readability by providing a more concise and expressive way to handle generator delegation, especially when using the Effect.ts library.

Motivating Example

Effect.ts is a powerful library for managing side effects in TypeScript applications. It provides tools to handle asynchronous operations, error management, and resource management in a type-safe manner. Effect.ts heavily relies on generators to make effect composition more readable and maintainable.

Consider the following example from Effect.ts official doc:

import {Effect } from "effect"

const program = Effect.gen ->
  transactionAmount := <- fetchTransactionAmount  // <- compiles to yield*
  // Retrieve the discount rate
  discountRate := <- fetchDiscountRate
  // Calculate discounted amount
  discountedAmount := <- applyDiscount transactionAmount, discountRate
  // Apply service charge
  finalAmount := addServiceCharge discountedAmount

  // Return the total amount after applying the charge
  return `Final amount to charge: ${finalAmount}`


// Execute the program and log the result
Effect
  .runPromise program
  .then console.log
// Output: Final amount to charge: 96

The proposed syntax sugar <- simplifies the code and aligns with Civet's goal of making the language more concise. This change reduces verbosity and makes the intent of yielding effects more explicit.

Effect.civet feels like a language with first-class effect management by introducing a special operator <-, while still backed by TypeScript's mature type system.

Prior Successful Collaboration

Civet has previously collaborated with SolidJS, demonstrating the benefits of integrating with other modern frameworks and libraries. Supporting Effect.ts would be another excellent collaboration, enhancing Civet's utility and appeal to developers who value maximum type safety in their applications.

Alignment with Civet Design Philosophy

This feature aligns with Civet's design philosophy in several ways:

  • Less Syntax: The <- operator reduces the verbosity of yield *, making the code more readable and concise.
  • Context Matters: The operator <- provides clear and context-specific behavior for generator delegation, enhancing code clarity.
  • Pragmatic: The proposed syntax is practical and improves the developer experience, especially for those who frequently use generator functions to manage effect.
  • Configurable: This feature can be introduced as an optional syntax sugar, allowing developers to adopt it based on their preference without breaking existing code.
  • Evolve: This feature helps civet evolving into a language managing side-effect

Thank you for considering this feature request. I believe it will enhance Civet's expressiveness and make generator delegation more intuitive for developers.

@edemaine edemaine added the proposal Proposal or discussion about a significant language feature label Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal Proposal or discussion about a significant language feature
Projects
None yet
Development

No branches or pull requests

2 participants