Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

trypluck'

Lib.trypluck' : ('a -> 'b option) -> 'a list -> ('b option * 'a list)

Pull an element out of a list.

An invocation trypluck' f [x1,...,xk,...,xn] returns either the pair

   (f(xk),[x1,...,xk-1,xk+1,...xn])

where xk has been lifted out of the list without disturbing the relative positions of the other elements, where f(xk) is SOME(v), and where f(xi) returns NONE for x1,...,xk-1; or it returns (NONE,[x1,...xn] when f applied to every element of the list returns NONE.

This is an 'option' version of the other library function trypluck.

Failure

Never fails.

See also

Lib.first, Lib.filter, Lib.mapfilter, Lib.tryfind, Lib.trypluck