Skip to content

Instantly share code, notes, and snippets.

@fitomad
Created November 26, 2018 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fitomad/3f1a3ec9112fbd5f36bd275e360e4bb4 to your computer and use it in GitHub Desktop.
Save fitomad/3f1a3ec9112fbd5f36bd275e360e4bb4 to your computer and use it in GitHub Desktop.
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