javaslang.algebra.Functor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javaslang-pure Show documentation
Show all versions of javaslang-pure Show documentation
A purely functional layer above Javaslang.
The newest version!
/* / \____ _ _ ____ ______ / \ ____ __ _______
* / / \/ \ / \/ \ / /\__\/ // \/ \ // /\__\ JΛVΛSLΛNG
* _/ / /\ \ \/ / /\ \\__\\ \ // /\ \ /\\/ \ /__\ \ Copyright 2014-2017 Javaslang, http://javaslang.io
* /___/\_/ \_/\____/\_/ \_/\__\/__/\__\_/ \_// \__/\_____/ Licensed under the Apache License, Version 2.0
*/
package javaslang.algebra;
import java.util.function.Function;
/**
* Defines a Functor by generalizing the {@code map} function.
*
* All instances of the Functor interface should obey the two functor laws:
*
* - {@code m.map(a -> a) ≡ m}
* - {@code m.map(f.compose(g)) ≡ m.map(g).map(f)}
*
* where "f, g ∈ Function".
*
* @param component type of this functor
* @author Daniel Dietrich
* @see The functor design pattern
* @since 1.1.0
*/
public interface Functor {
/**
* Applies a function {@code f} to the components of this Functor.
*
* @param 1st component type of the resulting Functor
* @param f a Function which maps the component of this Functor
* @return a new Functor
* @throws NullPointerException if {@code f} is null
*/
Functor map(Function super T, ? extends U> f);
}