
fj.data.Conversions Maven / Gradle / Ivy
package fj.data;
import fj.F;
import fj.P1;
import fj.Unit;
import fj.function.TryEffect0;
import fj.function.Effect0;
import fj.function.Effect1;
import fj.Try;
import fj.TryEffect;
import fj.Effect;
import fj.function.Try0;
import fj.function.Try1;
import java.io.IOException;
import static fj.Unit.unit;
import static fj.data.List.asString;
import static fj.data.List.fromString;
/**
* Functions that convert between data structure types.
*
* @version %build.number%
*/
public final class Conversions {
private Conversions() {
throw new UnsupportedOperationException();
}
// BEGIN List ->
/**
* A function that converts lists to arrays.
*
* @return A function that converts lists to arrays.
*/
public static F, Array> List_Array() {
return List::toArray;
}
/**
* A function that converts lists to streams.
*
* @return A function that converts lists to streams.
*/
public static F, Stream> List_Stream() {
return List::toStream;
}
/**
* A function that converts lists to options.
*
* @return A function that converts lists to options.
*/
public static F, Option> List_Option() {
return List::headOption;
}
/**
* A function that converts lists to eithers.
*
* @return A function that converts lists to eithers.
*/
public static F, F, Either>> List_Either() {
return a -> bs -> bs.toEither(a);
}
/**
* A function that converts lists to strings.
*/
public static final F, String> List_String = List::asString;
/**
* A function that converts lists to string buffers.
*/
public static final F, StringBuffer> List_StringBuffer = cs -> new StringBuffer(asString(cs));
/**
* A function that converts lists to string builders.
*/
public static final F, StringBuilder> List_StringBuilder = cs -> new StringBuilder(asString(cs));
// END List ->
// BEGIN Array ->
/**
* A function that converts arrays to lists.
*
* @return A function that converts arrays to lists.
*/
public static F, List> Array_List() {
return Array::toList;
}
/**
* A function that converts arrays to streams.
*
* @return A function that converts arrays to streams.
*/
public static F, Stream> Array_Stream() {
return Array::toStream;
}
/**
* A function that converts arrays to options.
*
* @return A function that converts arrays to options.
*/
public static F, Option> Array_Option() {
return Array::toOption;
}
/**
* A function that converts arrays to eithers.
*
* @return A function that converts arrays to eithers.
*/
public static F, F, Either>> Array_Either() {
return a -> bs -> bs.toEither(a);
}
/**
* A function that converts arrays to strings.
*/
public static final F, String> Array_String = cs -> {
final StringBuilder sb = new StringBuilder(cs.length());
cs.foreachDoEffect(sb::append);
return sb.toString();
};
/**
* A function that converts arrays to string buffers.
*/
public static final F, StringBuffer> Array_StringBuffer = cs -> {
final StringBuffer sb = new StringBuffer(cs.length());
cs.foreachDoEffect(sb::append);
return sb;
};
/**
* A function that converts arrays to string builders.
*/
public static final F, StringBuilder> Array_StringBuilder = cs -> {
final StringBuilder sb = new StringBuilder(cs.length());
cs.foreachDoEffect(sb::append);
return sb;
};
// END Array ->
// BEGIN Stream ->
/**
* A function that converts streams to lists.
*
* @return A function that converts streams to lists.
*/
public static F, List> Stream_List() {
return Stream::toList;
}
/**
* A function that converts streams to arrays.
*
* @return A function that converts streams to arrays.
*/
public static F, Array> Stream_Array() {
return Stream::toArray;
}
/**
* A function that converts streams to options.
*
* @return A function that converts streams to options.
*/
public static F, Option> Stream_Option() {
return Stream::toOption;
}
/**
* A function that converts streams to eithers.
*
* @return A function that converts streams to eithers.
*/
public static F, F, Either>> Stream_Either() {
return a -> bs -> bs.toEither(a);
}
/**
* A function that converts streams to strings.
*/
public static final F, String> Stream_String = cs -> {
final StringBuilder sb = new StringBuilder();
cs.foreachDoEffect(sb::append);
return sb.toString();
};
/**
* A function that converts streams to string buffers.
*/
public static final F, StringBuffer> Stream_StringBuffer = cs -> {
final StringBuffer sb = new StringBuffer();
cs.foreachDoEffect(sb::append);
return sb;
};
/**
* A function that converts streams to string builders.
*/
public static final F, StringBuilder> Stream_StringBuilder = cs -> {
final StringBuilder sb = new StringBuilder();
cs.foreachDoEffect(sb::append);
return sb;
};
// END Stream ->
// BEGIN Option ->
/**
* A function that converts options to lists.
*
* @return A function that converts options to lists.
*/
public static F
© 2015 - 2025 Weber Informatics LLC | Privacy Policy