fj.data.Option类的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(6.6k)|赞(0)|评价(0)|浏览(133)

本文整理了Java中fj.data.Option类的一些代码示例,展示了Option类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Option类的具体详情如下:
包路径:fj.data.Option
类名称:Option

Option介绍

[英]An optional value that may be none (no value) or some (a value). This type is a replacement for the use of null with better type checks.
[中]可选值,可以是none(无值)或some(a值)。这种类型可以通过更好的类型检查来替代null

代码示例

代码示例来源:origin: org.codehaus.mojo.unix/unix-pkg

/**
 * The same as calling {@link #FileEntry(Option, Option, UnixFsObject.RegularFile, Option)}
 * with <code>relative=false</code> and <code>realPath=null</code>.
 */
public FileEntry( Option<String> pkgClass, RegularFile file )
{
  this( pkgClass, some( FALSE ), file, Option.<File>none() );
}

代码示例来源:origin: com.stratio.mojo.unix/unix-sysv-pkg

protected String toString( FileAttributes attributes )
  {
    return attributes.mode.map( showOcalString ).orSome( "?" ) + " " +
      attributes.user.orSome( "?" ) + " " +
      attributes.group.orSome( "?" );
  }
}

代码示例来源:origin: org.codehaus.mojo.unix/unix-pkg

public boolean equalsIgnoreNull( PackageInfo that )
  {
    return instance.equals( that.instance ) && name.equals( that.name ) && category.equals( that.category ) &&
      arch.equals( that.arch ) && version.equals( that.version ) &&
      ( desc.isNone() || desc.some().equals( that.desc.some() ) ) &&
      ( pstamp.isNone() || pstamp.some().equals( that.pstamp.some() ) );
  }
}

代码示例来源:origin: org.functionaljava/functionaljava

/**
 * Binds the given function across the element of this optional value and the given optional value
 * with a final join.
 *
 * @param ob A given optional value to bind the given function with.
 * @param f  The function to apply to the element of this optional value and the given optional
 *           value.
 * @return A new optional value after performing the map, then final join.
 */
public final <B, C> Option<C> bind(final Option<B> ob, final F<A, F<B, C>> f) {
 return ob.apply(map(f));
}

代码示例来源:origin: org.functionaljava/functionaljava

/**
 * Returns the value of this optional value or the given argument.
 *
 * @param a The argument to return if this optiona value has no value.
 * @return The value of this optional value or the given argument.
 */
public final A orSome(final F0<A> a) {
 return isSome() ? some() : a.f();
}

代码示例来源:origin: org.functionaljava/functionaljava

/**
 * Filters elements from this optional value by returning only elements which produce
 * <code>true</code> when the given function is applied to them.
 *
 * @param f The predicate function to filter on.
 * @return A new optional value whose value matches the given predicate if it has one.
 */
public final Option<A> filter(final F<A, Boolean> f) {
 return isSome() ? f.f(some()) ? this : Option.none() : Option.none();
}

代码示例来源:origin: org.functionaljava/functionaljava

/**
 * Returns an optional non-empty string, or no value if the given string is empty.
 *
 * @param s A string to turn into an optional non-empty string.
 * @return an optional non-empty string, or no value if the given string is empty.
 */
public static Option<String> fromString(final String s) {
 return fromNull(s).bind(s1 -> {
  final Option<String> none = none();
  return s.length() == 0 ? none : some(s);
 });
}

代码示例来源:origin: org.codehaus.mojo.unix/unix-pkg

public Option<PackageInfo> getPackageInfo()
  {
    if ( instance.isNone() || name.isNone() || category.isNone() || arch.isNone() || version.isNone() )
    {
      return none();
    }
    return some(
      new PackageInfo( instance.some(), name.some(), category.some(), arch.some(), version.some(), desc,
               pstamp ) );
  }
}

代码示例来源:origin: org.functionaljava/functionaljava

/**
 * Traversable instance of Stream for Option.
 *
 * @return traversed value
 */
public final <B> Option<Stream<B>> traverseOption(F<A, Option<B>> f) {
 return this.foldRight1((a, acc) -> acc.bind(bs -> f.f(a).map(bs::cons)), some(Stream.nil()));
}

代码示例来源:origin: org.functionaljava/functionaljava

/**
 * Polymorphic Some prism
 */
public static <A, B> PPrism<Option<A>, Option<B>, A, B> pSome() {
 return pPrism(o -> o.<Either<Option<B>, A>>map(Either::right).orSome(Either.left(Option.none())), Option::some);
}

代码示例来源:origin: org.functionaljava/functionaljava

/**
 * Sequence through the option monad.
 *
 * @param a The list of option to sequence.
 * @return The option of list after sequencing.
 */
public static <A> Option<List<A>> sequence(final List<Option<A>> a) {
 return a.isEmpty() ?
     some(List.nil()) :
     a.head().bind(aa -> sequence(a.tail()).map(cons_(aa)));
}

代码示例来源:origin: org.functionaljava/functionaljava

/**
 * Returns the minimum (key, value) pair in the tree if the tree is not empty.
 */
public Option<P2<K, V>> min() {
  return tree.min().map(p -> p(p._1(), p._2().some()));
}

代码示例来源:origin: com.stratio.mojo.unix/unix-sysv-pkg

protected PrototypeEntry( Option<String> pkgClass, Option<Boolean> relative, U object )
{
  Validate.validateNotNull( pkgClass, relative, object );
  this.pkgClass = pkgClass.orSome( "none" );
  this.relative = relative;
  this.object = object;
}

代码示例来源:origin: org.functionaljava/functionaljava

/**
 * Returns a potential value that the given key maps to.
 *
 * @param k The key to look up in the hash map.
 * @return A potential value for the given key.
 */
public Option<V> get(final K k) {
 return fromNull(m.get(new Key(k)));
}

代码示例来源:origin: org.codehaus.mojo.unix/unix-pkg

public void addFile( FileObject fromFile, UnixFsObject.RegularFile file )
{
  fileSystem = fileSystem.addFile( new FileEntry( file.attributes.bind( findClassTag ), some( false ), file, some( asFile( fromFile ) ) ) );
}

代码示例来源:origin: org.functionaljava/functionaljava

/**
 * Performs function application within an optional value (applicative functor pattern).
 *
 * @param of The optional value of functions to apply.
 * @return A new optional value after applying the given optional value of functions through this
 *         optional value.
 */
public final <B> Option<B> apply(final Option<F<A, B>> of) {
 return of.bind(f -> map(f));
}

代码示例来源:origin: org.functionaljava/functionaljava

/**
 * Returns a potential value that the given key maps to.
 *
 * @param k The key to look up in the tree map.
 * @return A potential value for the given key.
 */
public Option<V> get(final K k) {
 return tree.lookup(p(k, Option.none())).bind(P2::_2);
}

代码示例来源:origin: org.functionaljava/functionaljava

/**
 * Promotes this function to map over an optional value.
 *
 * @return This function promoted to map over an optional value.
 */
public static <A, B> F<Option<A>, Option<B>> mapOption(final F<A, B> f) {
  return o -> o.map(f);
}

代码示例来源:origin: org.functionaljava/functionaljava

/**
 * Joins the given optional value of optional value using a bind operation.
 *
 * @param o The optional value of optional value to join.
 * @return A new optional value that is the join of the given optional value.
 */
public static <A> Option<A> join(final Option<Option<A>> o) {
 final F<Option<A>, Option<A>> id = identity();
 return o.bind(id);
}

代码示例来源:origin: org.functionaljava/functionaljava

/**
 * Returns the length of this optional value; 1 if there is a value, 0 otherwise.
 *
 * @return The length of this optional value; 1 if there is a value, 0 otherwise.
 */
public final int length() {
 return isSome() ? 1 : 0;
}

相关文章