You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Zero/ZeroLevel/Services/Fiber.cs

59 lines
1.4 KiB

using System;
using System.Collections.Generic;
using ZeroLevel.Services.Collections;
namespace ZeroLevel.Services
{
public class Fiber
{
class Step
{
public Func<IEverythingStorage, IEverythingStorage> _handler;
public Step _next;
}
5 months ago
Step _head = null!;
Step _tail = null!;
public Fiber()
{
}
public Fiber Add(Func<IEverythingStorage, IEverythingStorage> action)
{
5 months ago
if (_head == null!)
{
5 months ago
_head = _tail = new Step { _handler = action, _next = null! };
}
else
{
5 months ago
var s = new Step { _handler = action, _next = null! };
_tail._next = s;
_tail = s;
}
return this;
}
public IEnumerable<Func<IEverythingStorage, IEverythingStorage>> Iterate()
{
5 months ago
if (_head == null!) yield break;
var current = _head;
5 months ago
while (current != null!)
{
yield return current._handler;
current = current._next;
}
}
5 months ago
public IEverythingStorage Run(IEverythingStorage buffer = null!)
{
var storage = buffer;
foreach (var a in Iterate())
{
storage = a.Invoke(storage ?? new EverythingStorage());
}
return storage;
}
}
}

Powered by TurnKey Linux.