Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type Context = i32;
- fn run_sync_1(ctx: Context, next: impl Fn(Context) -> Context) -> Context {
- let ctx_new = ctx + 1;
- next(ctx_new)
- }
- fn run_sync_2(ctx: Context, next: impl Fn(Context) -> Context) -> Context {
- let ctx_new = ctx * 2;
- next(ctx_new)
- }
- fn run_sync_3(ctx: Context, _next: impl Fn(Context) -> Context) -> Context {
- ctx - 1
- }
- fn main() {
- // Sets to 1
- let chain_1 = |context, end| {
- run_sync_1(context, |context| {
- run_sync_2(context, |context| {
- run_sync_3(context, end)
- })
- })
- };
- // Adds 3
- let chain_2 = |context, end| {
- run_sync_1(context, |context| {
- run_sync_1(context, |context| {
- run_sync_1(context, end)
- })
- })
- };
- // ((3 + 1) * 2) - 1 = 7
- println!("results: {}", chain_2(0, |context| {
- chain_1(context, |_| {
- panic!("Error!")
- })
- }));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement