本文整理了Java中fj.data.List.single()
方法的一些代码示例,展示了List.single()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。List.single()
方法的具体详情如下:
包路径:fj.data.List
类名称:List
方法名:single
[英]Returns a list of one element containing the given value.
[中]返回包含给定值的一个元素的列表。
代码示例来源:origin: org.functionaljava/functionaljava
/**
* Promotes this function so that it returns its result in a List. Kleisli arrow for List.
*
* @return This function promoted to return its result in a List.
*/
public static <A, B> F<A, List<B>> listK(final F<A, B> f) {
return a -> List.single(f.f(a));
}
代码示例来源:origin: no.arktekk.unix/unix-common
public List<String> toList()
{
int i = string.lastIndexOf( '/' );
if ( i == -1 )
{
return List.single( string );
}
List<String> list = List.single( string.substring( i + 1 ) );
String s = string.substring( 0, i );
do
{
i = s.lastIndexOf( '/' );
if ( i == -1 )
{
return list.cons( s );
}
list = list.cons( s.substring( i + 1 ) );
s = s.substring( 0, i );
}
while ( true );
}
代码示例来源:origin: no.arktekk.unix/unix-common
public FileAttributes addTag( String tag )
{
return new FileAttributes( user, group, mode, tags.append( single( tag ) ) );
}
代码示例来源:origin: org.functionaljava/functionaljava
/**
* Returns a single element list if this projection has a value, otherwise an empty list.
*
* @return A single element list if this projection has a value, otherwise an empty list.
*/
public List<B> toList() {
return e.isRight() ? single(value()) : List.nil();
}
代码示例来源:origin: org.functionaljava/functionaljava
/**
* Returns a single element list if this projection has a value, otherwise an empty list.
*
* @return A single element list if this projection has a value, otherwise an empty list.
*/
public List<A> toList() {
return e.isLeft() ? single(value()) : List.nil();
}
代码示例来源:origin: org.functionaljava/functionaljava
/**
* Returns a nonempty list with the elements of this vector.
*
* @return a nonempty list with the elements of this vector.
*/
public NonEmptyList<A> toNonEmptyList() {
return NonEmptyList.nel(_1(), List.single(_2()));
}
代码示例来源:origin: org.functionaljava/functionaljava
/**
* Returns the list of final segments of this list, longest first.
*
* @return The list of final segments of this list, longest first.
*/
public final List<List<A>> tails() {
return isEmpty() ? single(List.nil()) : cons(this, tail().tails());
}
代码示例来源:origin: org.functionaljava/functionaljava
public final Validation<List<E>, T> accumulate() {
if (isFail()) {
return fail(List.single(fail()));
} else {
return success(success());
}
}
代码示例来源:origin: org.functionaljava/functionaljava
public final <B> List<List<B>> traverseList(final F<A, List<B>> f) {
return foldRight(
(a, acc) -> f.f(a).bind(b -> acc.map(bs -> bs.cons(b))),
single(List.nil()));
}
代码示例来源:origin: org.functionaljava/functionaljava
public final <B> Validation<List<E>, B> accumulate(F<T, B> f) {
if (isFail()) {
return fail(List.single(fail()));
} else {
return success(f.f(success()));
}
}
代码示例来源:origin: org.functionaljava/functionaljava
@Override
public F<S, List<S>> modifyListF(final F<A, List<A>> f) {
return s -> getOption.f(s).<List<S>> option(
() -> List.single(s),
t -> f.f(t).map(b -> set.f(b).f(s))
);
}
代码示例来源:origin: org.functionaljava/functionaljava
/**
* Returns the list of initial segments of this list, shortest first.
*
* @return The list of initial segments of this list, shortest first.
*/
public final List<List<A>> inits() {
List<List<A>> s = single(List.nil());
if (isNotEmpty())
s = s.append(tail().inits().map(List.<A>cons().f(head())));
return s;
}
代码示例来源:origin: novarto-oss/sane-dbc
@Test public void testIt()
{
assertThat(awaitSuccess(dbi.submit(insert("x"))), is(1));
assertThat(awaitSuccess(dbi.submit(selectAll())), is(single("x")));
SQLException ex = new SQLException("failed i have");
assertThat(
awaitFailure(dbi.transact(new DB<Unit>()
{
@Override public Unit run(Connection c) throws SQLException
{
insert("a").run(c);
insert("b").run(c);
throw ex;
}
})),
is(ex)
);
assertThat(awaitSuccess(dbi.submit(selectAll())), is(single("x")));
SQLException noConn = new SQLException("no connection");
AsyncDbInterpreter noConnection = new AsyncDbInterpreter(() -> {
throw noConn;
}, executor);
assertThat(awaitFailure(noConnection.transact(insert("alabala"))), is(noConn));
assertThat(awaitSuccess(dbi.submit(selectAll())), is(single("x")));
assertThat(
awaitSuccess(dbi.transact(insert("y").bind(ignore -> insert("z")).map(ignore2 -> Unit.unit()))),
is(Unit.unit())
);
assertThat(awaitSuccess(dbi.submit(selectAll())), is(arrayList("x", "y", "z")));
}
代码示例来源:origin: novarto-oss/sane-dbc
@Test public void testIt()
{
assertThat(DB.submit(insert("x")).f(), is(success(1)));
assertThat(DB.submit(selectAll()).f(), is(success(single("x"))));
SQLException ex = new SQLException("failed i have");
assertThat(
DB.transact(new DB<Unit>()
{
@Override public Unit run(Connection c) throws SQLException
{
insert("a").run(c);
insert("b").run(c);
throw ex;
}
}).f(),
is(fail(ex))
);
assertThat(DB.submit(selectAll()).f(), is(success(single("x"))));
SQLException noConn = new SQLException("no connection");
ValidationDbInterpreter noConnection = new ValidationDbInterpreter(() -> {
throw noConn;
});
assertThat(noConnection.transact(insert("alabala")).f(), is(fail(noConn)));
assertThat(DB.submit(selectAll()).f(), is(success(single("x"))));
assertThat(
DB.transact(insert("y").bind(ignore -> insert("z")).map(ignore2 -> Unit.unit())).f(),
is(success(Unit.unit()))
);
assertThat(DB.submit(selectAll()).f(), is(success(arrayList("x", "y", "z"))));
}
代码示例来源:origin: novarto-oss/sane-dbc
.orSome(() -> soFar.set(employee.departmentId, List.single(employee)));
},
代码示例来源:origin: no.arktekk.unix/unix-sysv-pkg
public List<String> toList()
{
F<List<String>, String> folder = List.<String, String>foldLeft().f( joiner.f( " " ) ).f( "" );
F<List<String>, String> stringF = FunctionF.compose( curry( concat, "CLASSES=" ), trim, folder );
List<Option<String>> list = List.<Option<String>>single( some( "ARCH=" + arch ) ).
cons( some( "CATEGORY=" + category ) ).
cons( some( "NAME=" + name ) ).
cons( some( "PKG=" + pkg ) ).
cons( some( "VERSION=" + version ) ).
cons( pstamp.map( curry( concat, "PSTAMP=" ) ) ).
cons( desc.map( curry( concat, "DESC=" ) ) ).
cons( email.map( curry( concat, "EMAIL=" ) ) ).
cons( iif( List.<String>isNotEmpty_(), classes ).map( stringF ) );
return Option.somes( list ).reverse();
}
代码示例来源:origin: com.stratio.mojo.unix/unix-sysv-pkg
public List<String> toList()
{
F<List<String>, String> folder = List.<String, String>foldLeft().f( joiner.f( " " ) ).f( "" );
F<List<String>, String> stringF = FunctionF.compose( curry( concat, "CLASSES=" ), trim, folder );
List<Option<String>> list = List.<Option<String>>single( some( "ARCH=" + arch ) ).
cons( some( "CATEGORY=" + category ) ).
cons( some( "NAME=" + name ) ).
cons( some( "PKG=" + pkg ) ).
cons( some( "VERSION=" + version ) ).
cons( pstamp.map( curry( concat, "PSTAMP=" ) ) ).
cons( desc.map( curry( concat, "DESC=" ) ) ).
cons( email.map( curry( concat, "EMAIL=" ) ) ).
cons( size.map( curry( concat, "SIZE=" ) ) ).
cons( iif( List.<String>isNotEmpty_(), classes ).map( stringF ) );
return Option.somes( list ).reverse();
}
内容来源于网络,如有侵权,请联系作者删除!