2013-11-19 21:03:46 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "kernel/for_each_fn.h"
|
2014-02-16 18:15:00 +00:00
|
|
|
#include "kernel/expr.h"
|
2013-11-19 21:03:46 +00:00
|
|
|
|
|
|
|
namespace lean {
|
2014-07-24 01:09:58 +00:00
|
|
|
/** \brief Return a subexpression of \c e that satisfies the predicate \c p. */
|
|
|
|
template<typename P> optional<expr> find(expr const & e, P p) {
|
|
|
|
optional<expr> result;
|
|
|
|
for_each(e, [&](expr const & e, unsigned offset) {
|
|
|
|
if (result) {
|
|
|
|
return false;
|
|
|
|
} else if (p(e, offset)) {
|
|
|
|
result = e;
|
|
|
|
return false;
|
2013-11-19 21:03:46 +00:00
|
|
|
} else {
|
2014-07-24 01:09:58 +00:00
|
|
|
return true;
|
2013-11-19 21:03:46 +00:00
|
|
|
}
|
2014-07-24 01:09:58 +00:00
|
|
|
});
|
|
|
|
return result;
|
2013-11-19 21:03:46 +00:00
|
|
|
}
|
|
|
|
}
|