<commit_before>funj
====

Collections and functional tools to complete the missing parts of Java/Guava.

To use with Maven:

	<dependency>
		<groupId>com.tek271</groupId>
		<artifactId>funj</artifactId>
		<version>1.0.0</version>
	</dependency>


Here is a list of some of the interesting parts:

CollectionTools
---------------

Let SomeEntity be a class with a property/field/getter named "id" of type long, and
a property "name" of type String.

	List<SomeEntity> entities = getEntities();
	Map<Long, SomeEntity> map = toMap(entities, "id");

Now the key in map is the id of SomeEntity, while the value is the SomeEntity object.

Now suppose you want to group entities by something which is not unique:

	Multimap<String, SomeEntity> toMultimap(entities, "name");


Finder
------
To find a list of objects with a matching property value:

	List<SomeEntity> foundList = findAll(entities, "id", 1, 2)

Will find entities whose id is either 1 or 2

	SomeEntity found = findFirst(entities, "name", "joe")

Will find the entity whose name property equals "joe"


Mapper
------
To extract/pluck a property from a list of entities:

	List<Long> ids = pluck(entities, "id");

To map the members of list using a callback function:

	List<Long> numbers = map(entities, this, "doubleTheId");

Assuming the ids where [1, 2, 3], numbers will have: [2, 4, 6].

The callback should be implemented as this:

	long doubleTheId(SomeEntity entity) {
		return entity.id * 2;
	}
<commit_msg>updated README.md with more details<commit_after>funj
====

Collections and functional tools to complete the missing parts of Java/Guava.

To use with Maven:

	<dependency>
		<groupId>com.tek271</groupId>
		<artifactId>funj</artifactId>
		<version>1.0.0</version>
	</dependency>


For the examples given below, suppose we have a class *Cat*

```Java
	class Cat {
		public long id;
		public String name;
		public int price;
		private String color;
		public String getColor() { return color; }
		public void setColor(String color) { this.color = color; }
	}
```

Additionally, suppose that we have a method `getCats()` which returns a list
of `Cat`s.

**Note:** This library can access either properties with getters/setters or fields
by name directly.

CollectionTools
---------------
To convert a collection to a map using one of collection's items properties
as a key:

	List<Cat> cats = getCats();
	Map<Long, Cat> map = toMap(cats, "id");

Now the key in map is the id of Cat, while the value is the Cat object.

But suppose you want to group cats by something which is not unique:

	com.google.common.collect.Multimap<String, Cat> multimap = toMultimap(cats, "color");

To check if a collection is null or empty:

	isEmpty(cats)


Finder
------
To find a list of objects with a matching property value:

	List<Cat> foundList = findAll(cats, "id", 1, 2);

Will find cats whose id is either 1 or 2.

	Cat found = findFirst(cats, "name", "tom");

Will find the cat whose name property equals "tom"


Mapper
------
To extract/pluck a property from a list of cats:

	List<Long> ids = pluck(cats, "id");

To extract/pluck a key and value from a list of cats and create a map:

	Map<Long, String> idsAndColors = pluckKeyAndValue(cats, "id", "color");

To map members of a list using a callback function:

Suppose that we have 3 cats with prices 10, 11, and 12. Also suppose that we
have this *callback* function:

	long doubleThePrice(Cat cat) {
		return cat.price * 2;
	}

If you call `map()` as this:

	List<Integer> prices = map(cats, this, "doubleThePrice");

The prices list will have: [20, 22, 24].

**Note** The `map()` method is overloaded to support both static and dynamic callback
methods.

{'fraction_non_alphanumeric': 0.10790190735694823, 'fraction_numerical': 0.0111716621253406, 'mean_word_length': 3.9474393530997305, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1233651', 'n_tokens_mistral': 1201, 'n_tokens_neox': 1109, 'n_words': 497}