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

Unify polymorphic output handling #805

Open
mijicd opened this issue Apr 6, 2023 · 7 comments
Open

Unify polymorphic output handling #805

mijicd opened this issue Apr 6, 2023 · 7 comments
Labels
enhancement New feature or request
Milestone

Comments

@mijicd
Copy link
Member

mijicd commented Apr 6, 2023

Some Redis commands return a different type of output depending on their input. We need to collect them and uniformly represent them. There are a few approaches that come to mind:

  • Create a dedicated response ADT for each such command; this approach causes an additional user-land effort.
  • Create response-specific functions, e.g., set and setGet; this approach maximizes usability on the price of slight divergence from Redis naming and proliferation of exposed functions.
@mijicd mijicd added the enhancement New feature or request label Apr 6, 2023
@mijicd
Copy link
Member Author

mijicd commented Apr 6, 2023

cc @drmarjanovic @mvelimir

@jxnu-liguobin
Copy link
Collaborator

I believe that client goals should include ease of use

@mijicd
Copy link
Member Author

mijicd commented Apr 6, 2023

@jxnu-liguobin 💯

@mijicd
Copy link
Member Author

mijicd commented Apr 6, 2023

Alternatively, as suggested by @drmarjanovic we might be able to utilize ResultBuilder .

@mijicd mijicd added this to the 0.3.0 milestone Apr 6, 2023
@mberndt123
Copy link
Contributor

I would not recommend using a response ADT, because then you need to pattern match against the return value and have to deal with cases that you know can't happen due to the parameters that were passed to the function. IOW it'd force you to write dead code.

There are two ways in Scala to model a function that returns different types depending on its input parameters.

The first is GADTs:

sealed trait Want[A]
object WantString extends Want[String]
object WantInt extends Want[Int]

def foo[A](want: Want[A]): A =
  want match {
    case WantString => "spam and eggs"
    case WantInt => 42
  }
val x: Int = foo(WantInt)

The second is abstract type members:

sealed trait Want {
  type Ret
  def value: Ret
}
object WantInt extends Want {
  type Ret = Int
  def value: Int = 42
}
object WantString extends Want {
  type Ret = String
  def value: String = "spam and eggs"
}
def foo(want: Want): want.Ret =
  want.value
val x: Int = foo(WantInt)

@mijicd
Copy link
Member Author

mijicd commented Nov 12, 2023

@mberndt123 Correct. I mentioned a few that came to my mind, the ticket is fully open for experimentation.

@mberndt123
Copy link
Contributor

mberndt123 commented Nov 13, 2023

Yeah sure, so I wanted to add what came to my mind 😉

@mijicd mijicd modified the milestones: 0.3.0, 2.0.0 Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants