Remove Identity

This commit is contained in:
Paul Campbell 2018-06-26 07:22:32 +01:00
parent 18aa6406ef
commit 2f5b01f460
3 changed files with 2 additions and 87 deletions

View file

@ -4,10 +4,11 @@ CHANGELOG
0.7.0
-----
* Remove `Identity`
* Add `Result`
* Moved `Maybe` to `net.kemitix.mon.maybe.Maybe`
* `Maybe` is now a Monad
* Add `Maybe.stream()`
* Deprecate `Maybe.fromOptional(Optional)`
0.6.0
-----

View file

@ -1,45 +0,0 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2017 Paul Campbell
*
* 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.
*/
package net.kemitix.mon;
import lombok.RequiredArgsConstructor;
import java.util.function.Function;
/**
* Identity.
*
* @param <T> the type of the identity content
*
* @author Paul Campbell (pcampbell@kemitix.net)
*/
@RequiredArgsConstructor
class Identity<T> implements Functor<T, Identity<?>> {
private final T value;
@Override
public <R> Identity<R> map(final Function<T, R> f) {
return new Identity<>(f.apply(value));
}
}

View file

@ -1,41 +0,0 @@
package net.kemitix.mon;
import org.assertj.core.api.WithAssertions;
import org.junit.Test;
/**
* Tests for {@link Identity}.
*
* @author Paul Campbell (pcampbell@kemitix.net)
*/
public class IdentityTest implements WithAssertions {
@Test
public void canMapIdentityFromStringToInteger() {
//given
final Identity<String> idString = new Identity<>("abc");
//when
final Identity<Integer> idInt = idString.map(String::length);
//then
assertIdentityContains(idInt, 3);
}
private <T> void assertIdentityContains(final Identity<T> identity, final T expected) {
identity.map(id -> assertThat(id).isEqualTo(expected));
}
@Test
public void canFluentlyComposeFunctions() {
//given
final Customer customer = new Customer(new Address("Park Place"));
//when
final Identity<byte[]> idBytes = new Identity<>(customer).map(Customer::getAddress)
.map(Address::getStreet)
.map((String s) -> s.substring(0, 3))
.map(String::toLowerCase)
.map(String::getBytes);
//then
assertIdentityContains(idBytes, "par".getBytes());
}
}