Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class Pool<Element>
{
/// Los elementos que gestionamos
public private(set) var elements: [Element]
/// Para saber los que hay disponibles
public var elementsAvailables: Int
{
return self.elements.count
}
/**
Nuevo pool con sus elementos
*/
public init(elements: [Element])
{
self.elements = elements
}
/**
Recuperamos un elemento
*/
public func getElement() -> Element?
{
self.elements.removeFirst()
}
/**
Reponemos el elemento
*/
public func restore(_ element: Element) -> Void
{
self.elements.append(element)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment