Skip to main content
added 6 characters in body
Source Link
Daniel T.
  • 3.1k
  • 21
  • 24

Your FancyControl isn't at the right level of monadic depth and so it doesn't fit properly inside the monad. As a matter of fact, if you createwere to create a fancy control that handles strings instead of streams of strings, then it would be a simple matter of flatMapping your stream product into a stream array FancyControl.

Your FancyControl isn't at the right level of monadic depth and so it doesn't fit properly inside the monad. As a matter of fact, if you create a fancy control that handles strings instead of streams of strings, then it would be a simple matter of flatMapping your stream product into a stream array FancyControl.

Your FancyControl isn't at the right level of monadic depth and so it doesn't fit properly inside the monad. As a matter of fact, if you were to create a fancy control that handles strings instead of streams of strings, then it would be a simple matter of flatMapping your stream product into a stream array FancyControl.

added 55 characters in body
Source Link
Daniel T.
  • 3.1k
  • 21
  • 24

We could try the same trick as your attempt 1 if we know the maximum number of comments allowed:

With the above, we end up with an array of FancyControls where commentFancyControl[n] displays productproducts.map(p => p.comment[n]). (Although, what does fancyControl[n] display if a particular product doesn't have a comment[n]?)

Or we could use your attempt 2 idea and "lift and flatten" the comments which will give us a 2-D ragged array of FancyControls which as you say:

[edited for the sake of the analogy] ... avoids all the disadvantages of attempt 1, but we are creating many single-use[element] arrays for every comment.

We could try the same trick if we know the maximum number of comments allowed:

With the above, we end up with an array of FancyControls where commentFancyControl[n] displays product.map(p => p.comment[n]). (Although, what does fancyControl[n] display if a particular product doesn't have a comment[n]?)

Or we could "lift and flatten" the comments which will give us a 2-D ragged array of FancyControls which as you say:

[edited for the sake of the analogy] ... avoids all the disadvantages of attempt 1, but we are creating many single-use arrays for every comment.

We could try the same trick as your attempt 1 if we know the maximum number of comments allowed:

With the above, we end up with an array of FancyControls where commentFancyControl[n] displays products.map(p => p.comment[n]). (Although, what does fancyControl[n] display if a particular product doesn't have a comment[n]?)

Or we could use your attempt 2 idea and "lift and flatten" the comments which will give us a 2-D ragged array of FancyControls which as you say:

[edited for the sake of the analogy] ... avoids all the disadvantages of attempt 1, but we are creating many single-[element] arrays for every comment.

edited body
Source Link
Daniel T.
  • 3.1k
  • 21
  • 24

With the above, we end up with an array of FancyControls where commentFancyControl[n] displays commentproduct.map(cp => cp.comment[n]). (Although, what does fancyControl[n] display if a particular commentproduct doesn't have a comment[n]?)

With the above, we end up with an array of FancyControls where commentFancyControl[n] displays comment.map(c => c.comment[n]). (Although, what does fancyControl[n] display if a particular comment doesn't have a comment[n]?)

With the above, we end up with an array of FancyControls where commentFancyControl[n] displays product.map(p => p.comment[n]). (Although, what does fancyControl[n] display if a particular product doesn't have a comment[n]?)

added 8 characters in body
Source Link
Daniel T.
  • 3.1k
  • 21
  • 24
Loading
Source Link
Daniel T.
  • 3.1k
  • 21
  • 24
Loading