Wrap a {@link CheckedUnaryOperator} in a {@link UnaryOperator}.
<p>
Example:
<code><pre>
Stream.of("a", "b", "c").map(Unchecked.unaryOperator(s -> {
if (s.length() > 10)
throw new Exception("Only short strings allowed");

return s;
}));
</pre></code>
966073
public static <T> UnaryOperator<T> unaryOperator(CheckedUnaryOperator<T> operator) {
        return unaryOperator(operator, THROWABLE_TO_RUNTIME_EXCEPTION);
    }
825746
public static FunctionalType primitiveUnaryOperator(PrimitiveType type) {
    switch (type.getKind()) {
      case INT:
        return new FunctionalType(
            Type.from(IntUnaryOperator.class),
            "applyAsInt",
            ImmutableList.of(type),
            type);

      case LONG:
        return new FunctionalType(
            Type.from(LongUnaryOperator.class),
            "applyAsLong",
            ImmutableList.of(type),
            type);

      case DOUBLE:
        return new FunctionalType(
            Type.from(DoubleUnaryOperator.class),
            "applyAsDouble",
            ImmutableList.of(type),
            type);

      default:
        throw new IllegalArgumentException("No primitive unary operator exists for " + type);
    }
  }
860940
public final BaseDescr unaryExpression() throws RecognitionException {
		BaseDescr result = null;


		BaseDescr ue =null;
		ParserRuleReturnScope left =null;

		try {
			// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:467:5: ( PLUS ue= unaryExpression | MINUS ue= unaryExpression | INCR primary | DECR primary |left= unaryExpressionNotPlusMinus )
			int alt49=5;
			switch ( input.LA(1) ) {
			case PLUS:
				{
				alt49=1;
				}
				break;
			case MINUS:
				{
				alt49=2;
				}
				break;
			case INCR:
				{
				alt49=3;
				}
				break;
			case DECR:
				{
				alt49=4;
				}
				break;
			case BOOL:
			case DECIMAL:
			case FLOAT:
			case HEX:
			case ID:
			case LEFT_PAREN:
			case LEFT_SQUARE:
			case LESS:
			case NEGATION:
			case NULL:
			case STAR:
			case STRING:
			case TILDE:
			case TIME_INTERVAL:
				{
				alt49=5;
				}
				break;
			default:
				if (state.backtracking>0) {state.failed=true; return result;}
				NoViableAltException nvae =
					new NoViableAltException("", 49, 0, input);
				throw nvae;
			}
			switch (alt49) {
				case 1 :
					// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:467:9: PLUS ue= unaryExpression
					{
					match(input,PLUS,FOLLOW_PLUS_in_unaryExpression2269); if (state.failed) return result;
					pushFollow(FOLLOW_unaryExpression_in_unaryExpression2273);
					ue=unaryExpression();
					state._fsp--;
					if (state.failed) return result;
					if ( state.backtracking==0 ) { if( buildDescr ) {
					            result = ue;
					            if( result instanceof AtomicExprDescr ) {
					                ((AtomicExprDescr)result).setExpression( "+" + ((AtomicExprDescr)result).getExpression() );
					            }
					        } }
					}
					break;
				case 2 :
					// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:474:7: MINUS ue= unaryExpression
					{
					match(input,MINUS,FOLLOW_MINUS_in_unaryExpression2291); if (state.failed) return result;
					pushFollow(FOLLOW_unaryExpression_in_unaryExpression2295);
					ue=unaryExpression();
					state._fsp--;
					if (state.failed) return result;
					if ( state.backtracking==0 ) { if( buildDescr ) {
					            result = ue;
					            if( result instanceof AtomicExprDescr ) {
					                ((AtomicExprDescr)result).setExpression( "-" + ((AtomicExprDescr)result).getExpression() );
					            }
					        } }
					}
					break;
				case 3 :
					// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:481:9: INCR primary
					{
					match(input,INCR,FOLLOW_INCR_in_unaryExpression2315); if (state.failed) return result;
					pushFollow(FOLLOW_primary_in_unaryExpression2317);
					primary();
					state._fsp--;
					if (state.failed) return result;
					}
					break;
				case 4 :
					// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:482:9: DECR primary
					{
					match(input,DECR,FOLLOW_DECR_in_unaryExpression2327); if (state.failed) return result;
					pushFollow(FOLLOW_primary_in_unaryExpression2329);
					primary();
					state._fsp--;
					if (state.failed) return result;
					}
					break;
				case 5 :
					// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:483:9: left= unaryExpressionNotPlusMinus
					{
					pushFollow(FOLLOW_unaryExpressionNotPlusMinus_in_unaryExpression2341);
					left=unaryExpressionNotPlusMinus();
					state._fsp--;
					if (state.failed) return result;
					if ( state.backtracking==0 ) { if( buildDescr ) { result = (left!=null?((DRL5Expressions.unaryExpressionNotPlusMinus_return)left).result:null); } }
					}
					break;

			}
		}

		catch (RecognitionException re) {
		    throw re;
		}

		finally {
			// do for sure before leaving
		}
		return result;
	}
418466
public <T> T evaluate(Evaluator<T> eval) throws IllegalArgumentException {
        try {
            Deque<T> stack = new ArrayDeque<>();
            for (Term<?> t : this) {
                if (t instanceof TermOperator) {
                    T val;
                    if (((TermOperator) t).getValue() == '~') {
                        T val1 = stack.pop();
                        val = eval.evaluateOperator(val1, (TermOperator) t);
                    } else {
                        T val2 = stack.pop();
                        T val1 = stack.pop();
                        val = eval.evaluateOperator(val1, val2, (TermOperator) t);
                    }
                    stack.push(val);
                } else if (t instanceof TermFloatValue) {
                    T val = eval.evaluateArgument((TermFloatValue) t);
                    stack.push(val);
                }
            }
            return stack.peek();
        } catch (NoSuchElementException e) {
            throw new IllegalArgumentException("Couldn't evaluate calc() expression", e);
        }
    }
885616
public ReadOnlyStyledDocument<PS, SEG, S> mapParagraphs(UnaryOperator<Paragraph<PS, SEG, S>> mapper) {
        int n = tree.getLeafCount();
        List<Paragraph<PS, SEG, S>> pars = new ArrayList<>(n);
        for(int i = 0; i < n; ++i) {
            pars.add(mapper.apply(tree.getLeaf(i)));
        }
        return new ReadOnlyStyledDocument<>(pars);
    }
522225
protected AstNode unary(boolean required) throws ScanException, ParseException {
		AstNode v = null;
		switch (token.getSymbol()) {
			case NOT:
				consumeToken();
				v = createAstUnary(unary(true), AstUnary.NOT);
				break;
			case MINUS:
				consumeToken();
				v = createAstUnary(unary(true), AstUnary.NEG);
				break;
			case EMPTY:
				consumeToken();
				v = createAstUnary(unary(true), AstUnary.EMPTY);
				break;
			case EXTENSION:
				if (getExtensionHandler(token).getExtensionPoint() == ExtensionPoint.UNARY) {
					v = getExtensionHandler(consumeToken()).createAstNode(unary(true));
					break;
				}
			default:
				v = value();
		}
		if (v == null && required) {
			fail(EXPR_FIRST);
		}
		return v;
	}
28292
public static <T> ObjIntConsumer<T> objIntConsumer(CheckedObjIntConsumer<T> consumer, Consumer<Throwable> handler) {
        return (t, u) -> {
            try {
                consumer.accept(t, u);
            }
            catch (Throwable e) {
                handler.accept(e);

                throw new IllegalStateException("Exception handler must throw a RuntimeException", e);
            }
        };
    }
501176
public static <T, E extends Throwable> @NonNull Predicate<T> unwrappingRethrowPredicate(final @NonNull ThrowingPredicate<T, E> predicate) {
    return input -> {
      try {
        return predicate.throwingTest(input);
      } catch(final Throwable t) {
        throw rethrow(unwrap(t));
      }
    };
  }
234283
public static TerminalOp<Integer, OptionalInt>
    makeInt(IntBinaryOperator operator) {
        Objects.requireNonNull(operator);
        class ReducingSink
                implements AccumulatingSink<Integer, OptionalInt, ReducingSink>, Sink.OfInt {
            private boolean empty;
            private int state;

            public void begin(long size) {
                empty = true;
                state = 0;
            }

            @Override
            public void accept(int t) {
                if (empty) {
                    empty = false;
                    state = t;
                }
                else {
                    state = operator.applyAsInt(state, t);
                }
            }

            @Override
            public OptionalInt get() {
                return empty ? OptionalInt.empty() : OptionalInt.of(state);
            }

            @Override
            public void combine(ReducingSink other) {
                if (!other.empty)
                    accept(other.state);
            }
        }
        return new ReduceOp<Integer, OptionalInt, ReducingSink>(StreamShape.INT_VALUE) {
            @Override
            public ReducingSink makeSink() {
                return new ReducingSink();
            }
        };
    }
45434
public static <T> ObjIntConsumer<T> objIntConsumer(CheckedObjIntConsumer<T> consumer) {
        return objIntConsumer(consumer, THROWABLE_TO_RUNTIME_EXCEPTION);
    }
795755
def _handle_unary_op(self, node, scope, ctxt, stream):
        
        self._dlog("handling unary op {}".format(node.op))

        special_switch = {
            "parentof"            : self._handle_parentof,
            "exists"            : self._handle_exists,
            "function_exists"    : self._handle_function_exists,
            "p++"                : self._handle_post_plus_plus,
            "p--"                : self._handle_post_minus_minus,
        }

        switch = {
            # for ++i and --i
            "++":        lambda x,v: x.__iadd__(1),
            "--":        lambda x,v: x.__isub__(1),

            "~":        lambda x,v: ~x,
            "!":        lambda x,v: not x,
            "-":        lambda x,v: -x,
            "sizeof":    lambda x,v: (fields.UInt64()+x._pfp__width()),
            "startof":    lambda x,v: (fields.UInt64()+x._pfp__offset),
        }

        if node.op not in switch and node.op not in special_switch:
            raise errors.UnsupportedUnaryOperator(node.coord, node.op)

        if node.op in special_switch:
            return special_switch[node.op](node, scope, ctxt, stream)

        field = self._handle_node(node.expr, scope, ctxt, stream)
        if type(field) is type:
            field = field()
        res = switch[node.op](field, 1)
        if type(res) is bool:
            new_res = field.__class__()
            new_res._pfp__set_value(1 if res == True else 0)
            res = new_res
        return res
834701
public final void assignmentOperator() throws RecognitionException {
		int assignmentOperator_StartIndex = input.index();

		try {
			if ( state.backtracking>0 && alreadyParsedRule(input, 109) ) { return; }

			// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1123:5: ( '=' | '+=' | '-=' | '*=' | '/=' | '&=' | '|=' | '^=' | '%=' | '<' '<' '=' | '>' '>' '=' | '>' '>' '>' '=' )
			int alt141=12;
			switch ( input.LA(1) ) {
			case 54:
				{
				alt141=1;
				}
				break;
			case 42:
				{
				alt141=2;
				}
				break;
			case 46:
				{
				alt141=3;
				}
				break;
			case 39:
				{
				alt141=4;
				}
				break;
			case 50:
				{
				alt141=5;
				}
				break;
			case 35:
				{
				alt141=6;
				}
				break;
			case 123:
				{
				alt141=7;
				}
				break;
			case 62:
				{
				alt141=8;
				}
				break;
			case 32:
				{
				alt141=9;
				}
				break;
			case 53:
				{
				alt141=10;
				}
				break;
			case 56:
				{
				int LA141_11 = input.LA(2);
				if ( (LA141_11==56) ) {
					int LA141_12 = input.LA(3);
					if ( (synpred212_Java()) ) {
						alt141=11;
					}
					else if ( (true) ) {
						alt141=12;
					}

				}

				else {
					if (state.backtracking>0) {state.failed=true; return;}
					int nvaeMark = input.mark();
					try {
						input.consume();
						NoViableAltException nvae =
							new NoViableAltException("", 141, 11, input);
						throw nvae;
					} finally {
						input.rewind(nvaeMark);
					}
				}

				}
				break;
			default:
				if (state.backtracking>0) {state.failed=true; return;}
				NoViableAltException nvae =
					new NoViableAltException("", 141, 0, input);
				throw nvae;
			}
			switch (alt141) {
				case 1 :
					// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1123:7: '='
					{
					match(input,54,FOLLOW_54_in_assignmentOperator4899); if (state.failed) return;
					}
					break;
				case 2 :
					// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1124:9: '+='
					{
					match(input,42,FOLLOW_42_in_assignmentOperator4909); if (state.failed) return;
					}
					break;
				case 3 :
					// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1125:9: '-='
					{
					match(input,46,FOLLOW_46_in_assignmentOperator4919); if (state.failed) return;
					}
					break;
				case 4 :
					// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1126:9: '*='
					{
					match(input,39,FOLLOW_39_in_assignmentOperator4929); if (state.failed) return;
					}
					break;
				case 5 :
					// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1127:9: '/='
					{
					match(input,50,FOLLOW_50_in_assignmentOperator4939); if (state.failed) return;
					}
					break;
				case 6 :
					// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1128:9: '&='
					{
					match(input,35,FOLLOW_35_in_assignmentOperator4949); if (state.failed) return;
					}
					break;
				case 7 :
					// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1129:9: '|='
					{
					match(input,123,FOLLOW_123_in_assignmentOperator4959); if (state.failed) return;
					}
					break;
				case 8 :
					// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1130:9: '^='
					{
					match(input,62,FOLLOW_62_in_assignmentOperator4969); if (state.failed) return;
					}
					break;
				case 9 :
					// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1131:9: '%='
					{
					match(input,32,FOLLOW_32_in_assignmentOperator4979); if (state.failed) return;
					}
					break;
				case 10 :
					// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1132:9: '<' '<' '='
					{
					match(input,53,FOLLOW_53_in_assignmentOperator4989); if (state.failed) return;
					match(input,53,FOLLOW_53_in_assignmentOperator4991); if (state.failed) return;
					match(input,54,FOLLOW_54_in_assignmentOperator4993); if (state.failed) return;
					}
					break;
				case 11 :
					// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1133:9: '>' '>' '='
					{
					match(input,56,FOLLOW_56_in_assignmentOperator5003); if (state.failed) return;
					match(input,56,FOLLOW_56_in_assignmentOperator5005); if (state.failed) return;
					match(input,54,FOLLOW_54_in_assignmentOperator5007); if (state.failed) return;
					}
					break;
				case 12 :
					// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1134:9: '>' '>' '>' '='
					{
					match(input,56,FOLLOW_56_in_assignmentOperator5017); if (state.failed) return;
					match(input,56,FOLLOW_56_in_assignmentOperator5019); if (state.failed) return;
					match(input,56,FOLLOW_56_in_assignmentOperator5021); if (state.failed) return;
					match(input,54,FOLLOW_54_in_assignmentOperator5023); if (state.failed) return;
					}
					break;

			}
		}
		catch (RecognitionException re) {
			reportError(re);
			recover(input,re);
		}
		finally {
			// do for sure before leaving
			if ( state.backtracking>0 ) { memoize(input, 109, assignmentOperator_StartIndex); }

		}
	}
814894
final public Selector Primary(boolean negated) throws ParseException {
                                      Selector ans; int op = Operator.PLUS;
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case 11:
    case TRUE:
    case FALSE:
    case IDENTIFIER:
    case QUOTED_IDENTIFIER:
    case INTEGER_LITERAL:
    case FLOATING_POINT_LITERAL:
    case STRING_LITERAL:
      ans = PrimaryNotPlusMinus(negated);
      break;
    case 7:
    case 8:
      op = PlusMinus();
                         negated ^= (op == Operator.MINUS);
      ans = Primary(negated);
      break;
    default:
      jj_la1[9] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
    {if (true) return ans;}
    throw new Error("Missing return statement in function");
  }
554611
final public Selector ComparisonPredicate() throws ParseException {
                                   Selector left, right; int op;
    left = Expression();
    op = ComparisonOperator();
    right = Expression();
    {if (true) return new OperatorImpl(op, left, right);}
    throw new Error("Missing return statement in function");
  }
1151962
public static void throwIfUnchecked(Throwable t) {
    Preconditions.checkNotNull(t);
    if (t instanceof RuntimeException) {
      throw (RuntimeException) t;
    }
    if (t instanceof Error) {
      throw (Error) t;
    }
  }
500587
public static <T, U extends Unifiable<? super T>> Choice<Unifier> unifyList(
      Unifier unifier,
      @Nullable List<U> toUnify,
      @Nullable final List<? extends T> targets,
      boolean allowVarargs) {
    if (toUnify == null && targets == null) {
      return Choice.of(unifier);
    } else if (toUnify == null
        || targets == null
        || (allowVarargs
            ? toUnify.size() - 1 > targets.size()
            : toUnify.size() != targets.size())) {
      return Choice.none();
    }
    Choice<Unifier> choice = Choice.of(unifier);
    int index;
    for (index = 0; index < toUnify.size(); index++) {
      U toUnifyNext = toUnify.get(index);
      if (allowVarargs && toUnifyNext instanceof URepeated) {
        final URepeated repeated = (URepeated) toUnifyNext;
        final int startIndex = index;
        return choice
            .condition(index + 1 == toUnify.size())
            .thenOption(
                new Function<Unifier, Optional<Unifier>>() {
                  @Override
                  public Optional<Unifier> apply(Unifier unifier) {
                    List<JCExpression> expressions = new ArrayList<>();
                    for (int j = startIndex; j < targets.size(); j++) {
                      Optional<Unifier> forked =
                          repeated.unify((JCTree) targets.get(j), unifier.fork()).first();
                      if (!forked.isPresent()) {
                        return Optional.absent();
                      }
                      JCExpression boundExpr = repeated.getUnderlyingBinding(forked.get());
                      if (boundExpr == null) {
                        return Optional.absent();
                      }
                      expressions.add(boundExpr);
                    }
                    unifier.putBinding(repeated.key(), expressions);
                    return Optional.of(unifier);
                  }
                });
      }
      if (index >= targets.size()) {
        return Choice.none();
      }
      choice = choice.thenChoose(unifications(toUnifyNext, targets.get(index)));
    }
    if (index < targets.size()) {
      return Choice.none();
    }
    return choice;
  }
217733
@Override
    protected String naryOperator(final NAryOperator operator, final String opString) {
        final List<Formula> operands = new ArrayList<>();
        for (final Formula op : operator) {
            operands.add(op);
        }
        final int size = operator.numberOfOperands();
        Collections.sort(operands, this.comparator);
        final StringBuilder sb = new StringBuilder();
        int count = 0;
        Formula last = null;
        for (final Formula op : operands) {
            if (++count == size) {
                last = op;
            } else {
                sb.append(operator.type().precedence() < op.type().precedence() ? toString(op) : bracket(op));
                sb.append(opString);
            }
        }
        if (last != null) {
            sb.append(operator.type().precedence() < last.type().precedence() ? toString(last) : bracket(last));
        }
        return sb.toString();
    }