With the introduction of Java 8 the first steps were taken to support functional programming. Unfortunately true functional programming is not yet supported.
Note: from version 1.1.0 the API class became deprecated
The library currently has the following groups of features that it adds on top of the default Java 11+ system:
- Functional interfaces, allowing for a more functional and declarative way of programming
- Immutable collections, supporting better declarative and safer operations
Value
, base interface for all entities within the extension frameworkOptional
, a purely functionally version of the Optional introduced in Java 8Try
, a functional implementation to wrap exception handlingCheckedConsumer
,CheckedFunction
,CheckedRunner
,CheckedSupplier
Sequence
, access to an ordered collectionSet
, a collection with unique entries based on the hash codeSortedSet
, a collection with unique entries based on the hash codeTuple
, a tuple implementation to store 2 or more entitiesMap
, a map implementation
Range
, a wrapper to create a date or date time range
To aid in using this library the JavaDoc is published online. This documentation contains information about the various interfaces present. The documentation is published at:
import com.jongsoft.lang.Collections;
class Main {
public static void main(String[] args){
// Instantiate a list, filter the strings by length and remove one
Sequence<String> myStrings = Collections.List("test", "string", "one")
.filter(s -> s.length() == 3)
.remove("test");
// The result will be: Sequence[one]
System.out.println(myStrings.toString());
}
}
import com.jongsoft.lang.Collections;
class Main {
public static class Entity {
private final String value;
public Entity(String value) {
this.value = value;
}
public boolean contains(String other) {
return value.contains(other);
}
}
public static void main(String[] args){
// Instantiate a list, filter the strings by length and remove one
Sequence<String> myStrings = Collections.List(
new Entity("sample"),
new Entity("more sample")
)
.distinctBy((e1, e2) => e1.contains(e2));
// The result will be: Sequence["sample"]
System.out.println(myStrings.toString());
}
}
To include this module use the Maven dependency below:
<dependency>
<groupId>com.jongsoft.lang</groupId>
<artifactId>language</artifactId>
<version>1.1.0</version>
</dependency>
The MIT License (MIT) Copyright (c) 2016-2020 Jong Soft Development
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.