Skip to content

Conversation

dvdvgt
Copy link
Collaborator

@dvdvgt dvdvgt commented Jun 10, 2025

This PR adds UFCS for blocks such that you can write { x => x + 42 }.foo { y => x * 2 }, for example.

@dvdvgt dvdvgt force-pushed the feature/ufcs-blocks branch from 8e72901 to 6adb66c Compare June 10, 2025 15:46
@dvdvgt
Copy link
Collaborator Author

dvdvgt commented Jun 10, 2025

Current caveat: When expecting a statement, a UFCS call with blocks is not allowed. For example

val x = { f1 }.foo { f2 }
              ^
expected ; but found .

fails since it expects a BlockStmt. This only works when explicitly returning:

val x = return { f1 }.foo { f2 }

@jiribenes
Copy link
Contributor

Related discussion: #845

@jiribenes
Copy link
Contributor

jiribenes commented Jun 15, 2025

What about, say,

interface State[T] {
  def get(): T
  def set(x: T): Unit
}

def increment() { st: State[T] }: Unit = {
  val current = st.get()
  st.set(current + 1)
}

def st: State[T] = ...

increment() {st}

Can we now write st.increment() or does it have to be {st}.increment()? Or is it not supported at all?

@jiribenes jiribenes added the experiment Experimental branch, do not merge! label Jun 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
experiment Experimental branch, do not merge!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants