当前位置: 首页>>代码示例>>Java>>正文


Java Function2.apply方法代码示例

本文整理汇总了Java中org.eclipse.xtext.xbase.lib.Functions.Function2.apply方法的典型用法代码示例。如果您正苦于以下问题:Java Function2.apply方法的具体用法?Java Function2.apply怎么用?Java Function2.apply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.xtext.xbase.lib.Functions.Function2的用法示例。


在下文中一共展示了Function2.apply方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: curry

import org.eclipse.xtext.xbase.lib.Functions.Function2; //导入方法依赖的package包/类
/**
 * Curries a function that takes two arguments.
 * 
 * @param function
 *            the original function. May not be <code>null</code>.
 * @param argument
 *            the fixed first argument of {@code function}.
 * @return a function that takes one argument. Never <code>null</code>.
 */
@Pure
public static <P1, P2, RESULT> Function1<P2, RESULT> curry(final Function2<? super P1, ? super P2, ? extends RESULT> function,
		final P1 argument) {
	if (function == null)
		throw new NullPointerException("function");
	return new Function1<P2, RESULT>() {
		@Override
		public RESULT apply(P2 p) {
			return function.apply(argument, p);
		}
	};
}
 
开发者ID:eclipse,项目名称:xtext-lib,代码行数:22,代码来源:FunctionExtensions.java

示例2: doRead

import org.eclipse.xtext.xbase.lib.Functions.Function2; //导入方法依赖的package包/类
public <T extends Object> T doRead(final URI uri, final Function2<? super Document, ? super XtextResource, ? extends T> work) {
  final URI resourceURI = uri.trimFragment();
  final ProjectManager projectMnr = this.getProjectManager(resourceURI);
  Resource _resource = null;
  if (projectMnr!=null) {
    _resource=projectMnr.getResource(resourceURI);
  }
  final XtextResource resource = ((XtextResource) _resource);
  if ((resource == null)) {
    return work.apply(null, null);
  }
  Document doc = this.getDocument(resource);
  Resource _resource_1 = projectMnr.getResource(resourceURI);
  return work.apply(doc, ((XtextResource) _resource_1));
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:16,代码来源:WorkspaceManager.java

示例3: stateJob

import org.eclipse.xtext.xbase.lib.Functions.Function2; //导入方法依赖的package包/类
public static Job stateJob(final String name, final AtomicInteger state,
    final Function2<IProgressMonitor, Integer, IStatus> fn) {
  return new WorkbenchJob(name) {
    @Override
    public IStatus runInUIThread(final IProgressMonitor monitor) {
      return fn.apply(monitor, state.incrementAndGet());
    }
  };
}
 
开发者ID:antlr4ide,项目名称:antlr4ide,代码行数:10,代码来源:Widgets.java

示例4: attempt

import org.eclipse.xtext.xbase.lib.Functions.Function2; //导入方法依赖的package包/类
/**
 * Calls some code safely.
 * Never throws an Exception.
 * @return
 * @return onError; if the code fails, otherwise the return value of call().
 */
public static <R, E1, E2> R attempt(final Function2<E1, E2, R> code,
        final E1 p1, final E2 p2, final R onError) {
    try {
        return code.apply(p1, p2);
    } catch (final Throwable t) {
        LOG.log(Level.SEVERE, t.getMessage(), t);
        return onError;
    }
}
 
开发者ID:skunkiferous,项目名称:Util,代码行数:16,代码来源:SafeCallExtension.java

示例5: execute

import org.eclipse.xtext.xbase.lib.Functions.Function2; //导入方法依赖的package包/类
public static String execute(final Function2<? super String, ? super Integer, ? extends String> f) {
  return f.apply("s", Integer.valueOf(10));
}
 
开发者ID:LorenzoBettini,项目名称:packtpub-xtext-book-examples,代码行数:4,代码来源:LambdaExamples.java

示例6: reduce

import org.eclipse.xtext.xbase.lib.Functions.Function2; //导入方法依赖的package包/类
/**
 * <p>
 * Applies the combinator {@code function} to all elements of the iterator in turn.
 * </p>
 * <p>
 * One of the function parameters is an element of the iterator, and the other is the result of previous application
 * of the function. The seed of the operation is the first element in the iterator. The second value is computed by
 * applying the function to the seed together with the second element of the iterator. The third value is computed
 * from the previous result together with the third element and so on. In other words, the previous result of each
 * step is taken and passed together with the next element to the combinator function.
 * </p>
 * <p>
 * If the iterator is empty, <code>null</code> is returned.
 * </p>
 * <p>
 * More formally, given an iterator {@code [a, b, c, d]} and a function {@code f}, the result of {@code reduce} is
 * <code>f(f(f(a, b), c), d)</code>
 * </p>
 * 
 * @param iterator
 *            the to-be-reduced iterator. May not be <code>null</code>.
 * @param function
 *            the combinator function. May not be <code>null</code>.
 * @return the last result of the applied combinator function or <code>null</code> for the empty input.
 */
public static <T> T reduce(Iterator<? extends T> iterator, Function2<? super T, ? super T, ? extends T> function) {
	if (function == null)
		throw new NullPointerException("function");
	if (iterator.hasNext()) {
		T result = iterator.next();
		while (iterator.hasNext()) {
			result = function.apply(result, iterator.next());
		}
		return result;
	} else {
		return null;
	}
}
 
开发者ID:eclipse,项目名称:xtext-lib,代码行数:39,代码来源:IteratorExtensions.java

示例7: fold

import org.eclipse.xtext.xbase.lib.Functions.Function2; //导入方法依赖的package包/类
/**
 * <p>
 * Applies the combinator {@code function} to all elements of the iterator in turn and uses {@code seed} as the
 * start value.
 * </p>
 * <p>
 * One of the function parameters is an element of the iterator, and the other is the result of previous application
 * of the function. The seed of the operation is explicitly passed to {@link #fold(Iterator, Object, org.eclipse.xtext.xbase.lib.Functions.Function2)
 * fold}. The first computed value is the result of the applied function for {@code seed} and the first element of
 * the iterator. This intermediate result together with the second element of the iterator produced the next result
 * and so on.
 * </p>
 * <p>
 * {@link #fold(Iterator, Object, org.eclipse.xtext.xbase.lib.Functions.Function2) fold} is similar to {@link #reduce(Iterator, org.eclipse.xtext.xbase.lib.Functions.Function2) reduce} but
 * allows a {@code seed} value and the combinator {@code function} may be asymmetric. It takes {@code T and R} and
 * returns {@code R}.
 * <p>
 * If the iterator is empty, <code>seed</code> is returned.
 * </p>
 * <p>
 * More formally, given an iterator {@code [a, b, c, d]}, a seed {@code initial} and a function {@code f}, the
 * result of {@code fold} is <code>f(f(f(f(initial, a), b), c), d)</code>
 * </p>
 * 
 * @param iterator
 *            the to-be-folded iterator. May not be <code>null</code>.
 * @param seed
 *            the initial value. May be <code>null</code>.
 * @param function
 *            the combinator function. May not be <code>null</code>.
 * @return the last result of the applied combinator function or <code>seed</code> for the empty input.
 */
public static <T, R> R fold(Iterator<T> iterator, R seed, Function2<? super R, ? super T, ? extends R> function) {
	R result = seed;
	while (iterator.hasNext()) {
		result = function.apply(result, iterator.next());
	}
	return result;
}
 
开发者ID:eclipse,项目名称:xtext-lib,代码行数:40,代码来源:IteratorExtensions.java


注:本文中的org.eclipse.xtext.xbase.lib.Functions.Function2.apply方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。