public class ListFunctionalSupport extends Object
Implements missing sequence functions in Java compared to Clojure. To make thing simpler, it only supports List type.
Constructor and Description |
---|
ListFunctionalSupport() |
Modifier and Type | Method and Description |
---|---|
static <T> List<T> |
drop(List<T> list,
int count)
Drop the first N elements and create a new list.
|
static <T> T |
first(List<T> list)
Get the first element in list.
|
static <T> T |
last(List<T> list)
get the last element in list.
|
static <T> List<T> |
rest(List<T> list)
Drop the only first element and create a new list.
|
static <T> List<T> |
takeLast(List<T> list,
int count)
Get the last N elements as a new list.
|
public static <T> T first(List<T> list)
Get the first element in list.
list
- list to getpublic static <T> T last(List<T> list)
get the last element in list.
list
- list to getpublic static <T> List<T> takeLast(List<T> list, int count)
Get the last N elements as a new list.
list
- list to getcount
- element count to getpublic static <T> List<T> drop(List<T> list, int count)
Drop the first N elements and create a new list.
list
- the listcount
- element count to droppublic static <T> List<T> rest(List<T> list)
Drop the only first element and create a new list. equivalent to drop(list, 1).
list
- the listListFunctionalSupport#drop(List, int)}
Copyright © 2022 The Apache Software Foundation. All rights reserved.