Closed emil14 closed 2 years ago
Sub-streams represents structured data. It's possible to avoid them and use lists, structs, maps
Follow classical FBP and introduce brackets
data type
There is already a type with 2 possible values - boolean. Just is it with union
type:
F 5 4 3 T F 2 1 0 T -> + -> 3 12
Use one sig
as open bracket and two as a closed (or vice versa)
() () 3 3 ()
() () 2 2 ()
-> + -> 4 6
brackets/bools
because it assumes some internal counting inside operatorsDo not use sub-streams to represent nested structures, use them to represent dynamic lists only
Go has builtin interfaces like Reader
or Closer
. Brackets might be implemented in a similar way using structures
{ open: bool }
{open:bool}
. Especially in case of gradual typingThe following form will make gradual typing problem less likely (although won't solve it completely)
{
bracket: {} // <- field and value signaling that message is a bracket
open: bool
}
Maybe there's a way to have substreams descried staticly just as we have port-types and like we would like to have types? Something like a:
bank-stream:
branch:
type: int
children: # must be array because there could be stream like (a (b b) (c c))
- account:
type: int
children:
- date:
type: int
- trans:
type: str
Maybe key names even can be ommited somehow?
Implement StreamItem<T>
generic type to operate on streams. This should solve "stream item is data OR bracket" typing problem.
{
bracket: bool
open: bool
data: T | null
}
Optional
type is still needed to represent T | null
, so data | bracket
problem just being replaced with another (maybe even worse) one{ bracket: false, data: null }
(maybe that's not the only one invalid value)
Sub streams with support of unlimited nesting allows asynchronously process nested data but they are not implemented and it seems to be very hard to achieve.
Example from FBP book:
Problems
Related to https://github.com/emil14/fbp-book-ru/blob/main/7_compos.md (sub-streams) and #58
Related to #58
Are staticly typed sub-streams even possible? Imagine a component with sub-stream sensitive inport - where does it takes input? From several different components that we hope sends their data in the right order?