4 ms·
export const Child2Animation = Co.Repeat( Co.Seq([ Co.SetState(Child2.Updaters.Core.a(replaceWith(1)).then( Child2.Updaters
by weatherlight 2y ago
export const Child2Animation =
Co.Repeat(
Co.Seq([
Co.SetState(Child2.Updaters.Core.a(replaceWith(1)).then(
Child2.Updaters.Core.b(replaceWith("")))),
Co.Wait(250),
Co.For(Range(0, 3))(
_ =>
Co.Seq([
Co.SetState(Child2.Updaters.Core.a(_ => _ * 2)),
Co.Wait(250),
Co.SetState(Child2.Updaters.Core.b(_ => _ + ".")),
Co.Wait(250),
])
)
])
);
> Not only is the code pretty self explanatory.
Is it though?
- boxed 2y ago> Ballerina integrates the state of the art in functional programming and even category theory. It's.. just typescript?
- gsuuon 2y agoI think a "before" comparison would've really helped with this example. I'd also argue a state machine approach has the added benefit of allowing you to enter the sequence at any point. If you use `Co.Seq` to e.g. build a form flow, it'd be hard to test or serialize into the middle of the sequence. There may be something interesting here but it's pretty hard to bite into.
- SebastianKra 2y ago> but the alternative implementation of state machines in any frontend framework would look terrible async function animation(setState, signal) { while (true) { setState("a", 1) setState("b", "") await wait(250) signal.throwIfAborted() for (_ of range(0, 3)) { setState("a", (_) => _ * 2) await wait(250) signal.throwIfAborted() setState("b", (_) => _ + ".") await wait(250) signal.throwIfAborted() } } }
- weatherlight 2y agoI love FP. but this is way more readable than the above. It doesn't fight the ergonomics of javascript.
- zarathustreal 2y agoYea, it is. Granted you have to understand the words used in the explanation. If your bar for “self-explanatory” is “teaches you both the words and the concepts” then there aren’t any self-explanatory frameworks at all?