import { Maybe } from '@typed/maybe' ; export class FifoQueue < A > { private queuables : A [ ] = [ ] ; enqueue ( queueable ) { this . queuables . push ( queueable ) ; } dequeue ( ) { return Maybe . of ( this . queuables . shift ( ) ) ; } peek ( ) { return Maybe . of ( this . queuables [ 0 ] ) ; } remove ( f ) { for ( let i = 0 ; i < this . queuables . length ; ++ i ) { if ( f ( this . queuables [ i ] ) ) { this . queuables . splice ( i , 1 ) ; -- i ; } } } some ( f ) { return this . queuables . some ( f ) ; } }