Comments (13)
Well, what I know is that in classical for { } yield { }, I'm accustomed to normalise to Xor[E, T]. So I want to make the really common use case (for me):
for {
a <- myService1() // Xor[E, A]
list_b <- myService2(a) //Xor[E, List[B]]
opt_c <- Xor.right(pure()) // with pure: Option[C]
res <- calculus(list_b, opt_c) // calculus(l: List[B], opt: Option[C]): Xor[E, D]
} yield {
res
}
To be portable in freek with the onion type explaining to future use what the program is about, i.e:
type O = Xor[E, ?] :&: Bulb
And whatever is needed to help scalac use the correct implicits - of course the leaner the better.
Hope it's clearer
from freek.
@fanf Can you precise a bit?
type O = Foo :&: Bar :&: Toto :&: Nil
Foo[Bar[List[Option[A]]].OnionN[_2, O]
// should OnionN seek in depth in type O or in type Foo[Bar[List[Option[A]]] ?
Last weekend, I've tried to simplify onionT vs onionP but I think it's impossible to get rid of that. It's the same as liftT
& lift
.
from freek.
Ah. This is exactly my wondering, to.
I believe that as an user (ie I don't know it it's possible), what I want is:
- my type O is what I want to normalise to, i.e the type of each line (the returned type of the whole program)
- for each line, I want to be able to "help" freek and let it knows that the type of the line should be explored N level deep only (or perhaps more robustly to traverse all and go back N levels as in "keep the last N containers").
Not sure it helps.
from freek.
now you would have to write something like:
type O = Xor[E, ?] :&: Bulb
for {
a <- myService1().onionT[O]
list_b <- myService2(a).onionP[O]
opt_c <- (()).onionT[O]
res <- calculus(list_b, opt_c) // calculus(l: List[B], opt: Option[C]): Xor[E, D]
} yield {
res
}
going further with implicits poses problems as soon as you encounter something like
for {
a <- myService1()
list_b <- myService2(a)
opt_c <- ().onionT[O]
res <- optc match {
case Some(c) => ...
case None => ...
}
// scalac is enable to unify types in the for-comprehension and you have to help it
} yield {
res
}
from freek.
OK, what about if calculus returns a Xor[E, List[D]]
?
(because of course, you're right, the problem in my use case is in the last returned type...)
from freek.
yep that' s the case I was speaking about... the important isn't only the O
but what you want to keep in your Xor[E, List[D]]
...
Xor[E, List[D]].onionN[O, 1]
would take Xor[E, List[D]]
, dig one layer in depth, keep List[D]
and lift it into the onion O.
but I think this onionN
can't be generalized...
from freek.
yep that' s the case I was speaking about... the important isn't only the O but what you want to keep in your Xor[E, List[D]]...
Xor[E, List[D]].onionN[O, 1] would take Xor[E, List[D]], dig one layer in depth, keep List[D] and lift it into the onion O.
That would be perfect!
but I think this onionN can't be generalized...
Oh :/
from freek.
Is it simpler if onionN[O, 1] consume the full stack and then drop one layer ? (no because it's the most external layer which is easely dropped ?)
from freek.
which full stack, the one you give in input or the onion?
from freek.
the input
from freek.
actually if you look at package.scala, for now, I had to create an implicit conversion for every stack F[A]
, F[G[A]]
, F[G[H[A]]]
... so I feel OnionN isn't so easy for now ;)
from freek.
oOOHHHhhoo. What a lib dev has to do to let the user think things are nice :))
from freek.
What @fanf said, but I understand it may not be feasible :)
from freek.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from freek.