Copyright 2008 - 2010 Tony Morris, Runar Bjarnason, Tom Adams, Brad Clow, Ricky Clarkson, Nick Partridge, Jason Zaugg

This software is released under an open source BSD licence.

fj
Class F<A,B>

java.lang.Object
  extended by fj.F<A,B>

public abstract class F<A,B>
extends java.lang.Object

A transformation or function from A to B. This type can be represented using the Java 7 closure syntax.


Constructor Summary
F()
           
 
Method Summary
<C> F<F<B,C>,F<A,C>>
andThen()
          First-class composition flipped.
<C> F<A,C>
andThen(F<B,C> g)
          Function composition flipped.
<C> F<F<A,F<B,C>>,F<A,C>>
apply()
          First-class function application in an environment.
<C> F<A,C>
apply(F<A,F<B,C>> g)
          Function application in an environment (Applicative Functor).
 F<A,Array<B>> arrayK()
          Promotes this function so that it returns its result in a Array.
<C> F<F<B,F<A,C>>,F<A,C>>
bind()
          First-class function binding.
<C> F<A,C>
bind(F<B,F<A,C>> g)
          Binds a given function across this function (Reader Monad).
 F<Actor<B>,Actor<A>> comapActor()
          Returns a function that comaps over a given actor.
 F<Equal<B>,Equal<A>> comapEqual()
          Promotes this function to map over an Equal as a contravariant functor.
 F<Hash<B>,Hash<A>> comapHash()
          Promotes this function to map over a Hash as a contravariant functor.
 F<Show<B>,Show<A>> comapShow()
          Promotes this function to map over a Show as a contravariant functor.
<C> F<A,Either<B,C>>
eitherLeftK()
          Promotes this function so that it returns its result on the left side of an Either.
<C> F<A,Either<C,B>>
eitherRightK()
          Promotes this function so that it returns its result on the right side of an Either.
abstract  B f(A a)
          Transform A to B.
<C> F<A,Validation<B,C>>
failK()
          Promotes this function so that it returns its result on the failure side of a Validation.
 F<Tree<A>,B> foldMapTree(Monoid<B> m)
          Returns a function that maps this function over a tree and folds it with the given monoid.
 F<A,IterableW<B>> iterableK()
          Promotes this function to return its value in an Iterable.
 F<A,P1<B>> lazy()
          Promotes this function so that it returns its result in a product-1.
 F<A,List<B>> listK()
          Promotes this function so that it returns its result in a List.
 F<Array<A>,Array<B>> mapArray()
          Promotes this function to map over a Array.
 F<P2<A,A>,P2<B,B>> mapBoth()
          Promotes this function to map over both elements of a pair.
<X> F<Validation<A,X>,Validation<B,X>>
mapFail()
          Promotes this function to map over the failure side of a Validation.
<C> F<P2<A,C>,P2<B,C>>
mapFst()
          Promotes this function to map over the first element of a pair.
 F<java.lang.Iterable<A>,IterableW<B>> mapIterable()
          Promotes this function to map over Iterables.
 java.util.concurrent.ArrayBlockingQueue<B> mapJ(java.util.concurrent.ArrayBlockingQueue<A> as)
          Maps this function over an ArrayBlockingQueue.
 java.util.ArrayList<B> mapJ(java.util.ArrayList<A> as)
          Maps this function over an ArrayList.
 java.util.concurrent.ConcurrentLinkedQueue<B> mapJ(java.util.concurrent.ConcurrentLinkedQueue<A> as)
          Maps this function over a ConcurrentLinkedQueue.
 java.util.concurrent.CopyOnWriteArrayList<B> mapJ(java.util.concurrent.CopyOnWriteArrayList<A> as)
          Maps this function over a CopyOnWriteArrayList.
 java.util.concurrent.CopyOnWriteArraySet<B> mapJ(java.util.concurrent.CopyOnWriteArraySet<A> as)
          Maps this function over a CopyOnWriteArraySet.
 java.util.concurrent.LinkedBlockingQueue<B> mapJ(java.util.concurrent.LinkedBlockingQueue<A> as)
          Maps this function over a LinkedBlockingQueue.
 java.util.LinkedList<B> mapJ(java.util.LinkedList<A> as)
          Maps this function over a LinkedList.
 java.util.concurrent.PriorityBlockingQueue<B> mapJ(java.util.concurrent.PriorityBlockingQueue<A> as)
          Maps this function over a PriorityBlockingQueue.
 java.util.PriorityQueue<B> mapJ(java.util.PriorityQueue<A> as)
          Maps this function over a PriorityQueue.
 java.util.concurrent.SynchronousQueue<B> mapJ(java.util.concurrent.SynchronousQueue<A> as)
          Maps this function over a SynchronousQueue.
 java.util.TreeSet<B> mapJ(java.util.TreeSet<A> as)
          Maps this function over a TreeSet.
<X> F<Either<A,X>,Either<B,X>>
mapLeft()
          Promotes this function to map over the left side of an Either.
 F<List<A>,List<B>> mapList()
          Promotes this function to map over a List.
 F<NonEmptyList<A>,NonEmptyList<B>> mapNel()
          Promotes this function to map over a NonEmptyList.
 F<Option<A>,Option<B>> mapOption()
          Promotes this function to map over an optional value.
 F<P1<A>,P1<B>> mapP1()
          Promotes this function to map over a product-1.
 F<Promise<A>,Promise<B>> mapPromise()
          Promotes this function to map over a Promise.
<X> F<Either<X,A>,Either<X,B>>
mapRight()
          Promotes this function to map over the right side of an Either.
 F<Set<A>,Set<B>> mapSet(Ord<B> o)
          Promotes this function to map over a Set.
<C> F<P2<C,A>,P2<C,B>>
mapSnd()
          Promotes this function to map over the second element of a pair.
 F<Stream<A>,Stream<B>> mapStream()
          Promotes this function to map over a Stream.
<X> F<Validation<X,A>,Validation<X,B>>
mapSuccess()
          Promotes this function to map over the success side of a Validation.
 F<Tree<A>,Tree<B>> mapTree()
          Promotes this function to map over a Tree.
 F<TreeZipper<A>,TreeZipper<B>> mapTreeZipper()
          Promotes this function to map over a TreeZipper.
 F<Zipper<A>,Zipper<B>> mapZipper()
          Promotes this function to map over a Zipper.
 F<A,NonEmptyList<B>> nelK()
          Promotes this function to return its value in a NonEmptyList.
<C> F<F<C,A>,F<C,B>>
o()
          First-class function composition
<C> F<C,B>
o(F<C,A> g)
          Function composition
<C> F<F<B,F<B,C>>,F<A,F<A,C>>>
on()
          Applies this function over the arguments of another function.
<C> F<A,F<A,C>>
on(F<B,F<B,C>> g)
          Applies this function over the arguments of another function.
 F<Validation<B,A>,B> onFail()
          Returns a function that returns the failure side of a given Validation, or this function applied to the success side.
 F<Either<B,A>,B> onLeft()
          Returns a function that returns the left side of a given Either, or this function applied to the right side.
 F<Either<A,B>,B> onRight()
          Returns a function that returns the right side of a given Either, or this function applied to the left side.
 F<Validation<A,B>,B> onSuccess()
          Returns a function that returns the success side of a given Validation, or this function applied to the failure side.
 F<A,Option<B>> optionK()
          Promotes this function so that it returns its result in an Option.
 F<A,Promise<B>> promiseK(Strategy<Unit> s)
          Promotes this function to a concurrent function that returns a Promise of a value.
 F<A,Set<B>> setK(Ord<B> o)
          Promotes this function to return its value in a Set.
 F<A,Stream<B>> streamK()
          Promotes this function so that it returns its result in a Stream.
<C> F<A,Validation<C,B>>
successK()
          Promotes this function so that it returns its result on the success side of an Validation.
 F<A,Tree<B>> treeK()
          Promotes this function to return its value in a Tree.
 F<A,TreeZipper<B>> treeZipperK()
          Promotes this function to return its value in a TreeZipper.
 F<A,Zipper<B>> zipperK()
          Promotes this function to return its value in a Zipper.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

F

public F()
Method Detail

f

public abstract B f(A a)
Transform A to B.

Parameters:
a - The A to transform.
Returns:
The result of the transformation.

o

public final <C> F<C,B> o(F<C,A> g)
Function composition

Parameters:
g - A function to compose with this one.
Returns:
The composed function such that this function is applied last.

o

public final <C> F<F<C,A>,F<C,B>> o()
First-class function composition

Returns:
A function that composes this function with another.

andThen

public final <C> F<A,C> andThen(F<B,C> g)
Function composition flipped.

Parameters:
g - A function with which to compose this one.
Returns:
The composed function such that this function is applied first.

andThen

public final <C> F<F<B,C>,F<A,C>> andThen()
First-class composition flipped.

Returns:
A function that invokes this function and then a given function on the result.

bind

public final <C> F<A,C> bind(F<B,F<A,C>> g)
Binds a given function across this function (Reader Monad).

Parameters:
g - A function that takes the return value of this function as an argument, yielding a new function.
Returns:
A function that invokes this function on its argument and then the given function on the result.

bind

public final <C> F<F<B,F<A,C>>,F<A,C>> bind()
First-class function binding.

Returns:
A function that binds another function across this function.

apply

public final <C> F<A,C> apply(F<A,F<B,C>> g)
Function application in an environment (Applicative Functor).

Parameters:
g - A function with the same argument type as this function, yielding a function that takes the return value of this function.
Returns:
A new function that invokes the given function on its argument, yielding a new function that is then applied to the result of applying this function to the argument.

apply

public final <C> F<F<A,F<B,C>>,F<A,C>> apply()
First-class function application in an environment.

Returns:
A function that applies a given function within the environment of this function.

on

public final <C> F<A,F<A,C>> on(F<B,F<B,C>> g)
Applies this function over the arguments of another function.

Parameters:
g - The function over whose arguments to apply this function.
Returns:
A new function that invokes this function on its arguments before invoking the given function.

on

public final <C> F<F<B,F<B,C>>,F<A,F<A,C>>> on()
Applies this function over the arguments of another function.

Returns:
A function that applies this function over the arguments of another function.

lazy

public final F<A,P1<B>> lazy()
Promotes this function so that it returns its result in a product-1. Kleisli arrow for P1.

Returns:
This function promoted to return its result in a product-1.

mapP1

public final F<P1<A>,P1<B>> mapP1()
Promotes this function to map over a product-1.

Returns:
This function promoted to map over a product-1.

optionK

public final F<A,Option<B>> optionK()
Promotes this function so that it returns its result in an Option. Kleisli arrow for Option.

Returns:
This function promoted to return its result in an Option.

mapOption

public final F<Option<A>,Option<B>> mapOption()
Promotes this function to map over an optional value.

Returns:
This function promoted to map over an optional value.

listK

public final F<A,List<B>> listK()
Promotes this function so that it returns its result in a List. Kleisli arrow for List.

Returns:
This function promoted to return its result in a List.

mapList

public final F<List<A>,List<B>> mapList()
Promotes this function to map over a List.

Returns:
This function promoted to map over a List.

streamK

public final F<A,Stream<B>> streamK()
Promotes this function so that it returns its result in a Stream. Kleisli arrow for Stream.

Returns:
This function promoted to return its result in a Stream.

mapStream

public final F<Stream<A>,Stream<B>> mapStream()
Promotes this function to map over a Stream.

Returns:
This function promoted to map over a Stream.

arrayK

public final F<A,Array<B>> arrayK()
Promotes this function so that it returns its result in a Array. Kleisli arrow for Array.

Returns:
This function promoted to return its result in a Array.

mapArray

public final F<Array<A>,Array<B>> mapArray()
Promotes this function to map over a Array.

Returns:
This function promoted to map over a Array.

comapActor

public final F<Actor<B>,Actor<A>> comapActor()
Returns a function that comaps over a given actor.

Returns:
A function that comaps over a given actor.

promiseK

public final F<A,Promise<B>> promiseK(Strategy<Unit> s)
Promotes this function to a concurrent function that returns a Promise of a value.

Parameters:
s - A parallel strategy for concurrent execution.
Returns:
A concurrent function that returns a Promise of a value.

mapPromise

public final F<Promise<A>,Promise<B>> mapPromise()
Promotes this function to map over a Promise.

Returns:
This function promoted to map over Promises.

eitherLeftK

public final <C> F<A,Either<B,C>> eitherLeftK()
Promotes this function so that it returns its result on the left side of an Either. Kleisli arrow for the Either left projection.

Returns:
This function promoted to return its result on the left side of an Either.

eitherRightK

public final <C> F<A,Either<C,B>> eitherRightK()
Promotes this function so that it returns its result on the right side of an Either. Kleisli arrow for the Either right projection.

Returns:
This function promoted to return its result on the right side of an Either.

mapLeft

public final <X> F<Either<A,X>,Either<B,X>> mapLeft()
Promotes this function to map over the left side of an Either.

Returns:
This function promoted to map over the left side of an Either.

mapRight

public final <X> F<Either<X,A>,Either<X,B>> mapRight()
Promotes this function to map over the right side of an Either.

Returns:
This function promoted to map over the right side of an Either.

onLeft

public final F<Either<B,A>,B> onLeft()
Returns a function that returns the left side of a given Either, or this function applied to the right side.

Returns:
a function that returns the left side of a given Either, or this function applied to the right side.

onRight

public final F<Either<A,B>,B> onRight()
Returns a function that returns the right side of a given Either, or this function applied to the left side.

Returns:
a function that returns the right side of a given Either, or this function applied to the left side.

iterableK

public final F<A,IterableW<B>> iterableK()
Promotes this function to return its value in an Iterable.

Returns:
This function promoted to return its value in an Iterable.

mapIterable

public final F<java.lang.Iterable<A>,IterableW<B>> mapIterable()
Promotes this function to map over Iterables.

Returns:
This function promoted to map over Iterables.

nelK

public final F<A,NonEmptyList<B>> nelK()
Promotes this function to return its value in a NonEmptyList.

Returns:
This function promoted to return its value in a NonEmptyList.

mapNel

public final F<NonEmptyList<A>,NonEmptyList<B>> mapNel()
Promotes this function to map over a NonEmptyList.

Returns:
This function promoted to map over a NonEmptyList.

setK

public final F<A,Set<B>> setK(Ord<B> o)
Promotes this function to return its value in a Set.

Parameters:
o - An order for the set.
Returns:
This function promoted to return its value in a Set.

mapSet

public final F<Set<A>,Set<B>> mapSet(Ord<B> o)
Promotes this function to map over a Set.

Parameters:
o - An order for the resulting set.
Returns:
This function promoted to map over a Set.

treeK

public final F<A,Tree<B>> treeK()
Promotes this function to return its value in a Tree.

Returns:
This function promoted to return its value in a Tree.

mapTree

public final F<Tree<A>,Tree<B>> mapTree()
Promotes this function to map over a Tree.

Returns:
This function promoted to map over a Tree.

foldMapTree

public final F<Tree<A>,B> foldMapTree(Monoid<B> m)
Returns a function that maps this function over a tree and folds it with the given monoid.

Parameters:
m - The monoid with which to fold the mapped tree.
Returns:
a function that maps this function over a tree and folds it with the given monoid.

treeZipperK

public final F<A,TreeZipper<B>> treeZipperK()
Promotes this function to return its value in a TreeZipper.

Returns:
This function promoted to return its value in a TreeZipper.

mapTreeZipper

public final F<TreeZipper<A>,TreeZipper<B>> mapTreeZipper()
Promotes this function to map over a TreeZipper.

Returns:
This function promoted to map over a TreeZipper.

failK

public final <C> F<A,Validation<B,C>> failK()
Promotes this function so that it returns its result on the failure side of a Validation. Kleisli arrow for the Validation failure projection.

Returns:
This function promoted to return its result on the failure side of a Validation.

successK

public final <C> F<A,Validation<C,B>> successK()
Promotes this function so that it returns its result on the success side of an Validation. Kleisli arrow for the Validation success projection.

Returns:
This function promoted to return its result on the success side of an Validation.

mapFail

public final <X> F<Validation<A,X>,Validation<B,X>> mapFail()
Promotes this function to map over the failure side of a Validation.

Returns:
This function promoted to map over the failure side of a Validation.

mapSuccess

public final <X> F<Validation<X,A>,Validation<X,B>> mapSuccess()
Promotes this function to map over the success side of a Validation.

Returns:
This function promoted to map over the success side of a Validation.

onFail

public final F<Validation<B,A>,B> onFail()
Returns a function that returns the failure side of a given Validation, or this function applied to the success side.

Returns:
a function that returns the failure side of a given Validation, or this function applied to the success side.

onSuccess

public final F<Validation<A,B>,B> onSuccess()
Returns a function that returns the success side of a given Validation, or this function applied to the failure side.

Returns:
a function that returns the success side of a given Validation, or this function applied to the failure side.

zipperK

public final F<A,Zipper<B>> zipperK()
Promotes this function to return its value in a Zipper.

Returns:
This function promoted to return its value in a Zipper.

mapZipper

public final F<Zipper<A>,Zipper<B>> mapZipper()
Promotes this function to map over a Zipper.

Returns:
This function promoted to map over a Zipper.

comapEqual

public final F<Equal<B>,Equal<A>> comapEqual()
Promotes this function to map over an Equal as a contravariant functor.

Returns:
This function promoted to map over an Equal as a contravariant functor.

comapHash

public final F<Hash<B>,Hash<A>> comapHash()
Promotes this function to map over a Hash as a contravariant functor.

Returns:
This function promoted to map over a Hash as a contravariant functor.

comapShow

public final F<Show<B>,Show<A>> comapShow()
Promotes this function to map over a Show as a contravariant functor.

Returns:
This function promoted to map over a Show as a contravariant functor.

mapFst

public final <C> F<P2<A,C>,P2<B,C>> mapFst()
Promotes this function to map over the first element of a pair.

Returns:
This function promoted to map over the first element of a pair.

mapSnd

public final <C> F<P2<C,A>,P2<C,B>> mapSnd()
Promotes this function to map over the second element of a pair.

Returns:
This function promoted to map over the second element of a pair.

mapBoth

public final F<P2<A,A>,P2<B,B>> mapBoth()
Promotes this function to map over both elements of a pair.

Returns:
This function promoted to map over both elements of a pair.

mapJ

public final java.util.concurrent.SynchronousQueue<B> mapJ(java.util.concurrent.SynchronousQueue<A> as)
Maps this function over a SynchronousQueue.

Parameters:
as - A SynchronousQueue to map this function over.
Returns:
A new SynchronousQueue with this function applied to each element.

mapJ

public final java.util.concurrent.PriorityBlockingQueue<B> mapJ(java.util.concurrent.PriorityBlockingQueue<A> as)
Maps this function over a PriorityBlockingQueue.

Parameters:
as - A PriorityBlockingQueue to map this function over.
Returns:
A new PriorityBlockingQueue with this function applied to each element.

mapJ

public final java.util.concurrent.LinkedBlockingQueue<B> mapJ(java.util.concurrent.LinkedBlockingQueue<A> as)
Maps this function over a LinkedBlockingQueue.

Parameters:
as - A LinkedBlockingQueue to map this function over.
Returns:
A new LinkedBlockingQueue with this function applied to each element.

mapJ

public final java.util.concurrent.CopyOnWriteArraySet<B> mapJ(java.util.concurrent.CopyOnWriteArraySet<A> as)
Maps this function over a CopyOnWriteArraySet.

Parameters:
as - A CopyOnWriteArraySet to map this function over.
Returns:
A new CopyOnWriteArraySet with this function applied to each element.

mapJ

public final java.util.concurrent.CopyOnWriteArrayList<B> mapJ(java.util.concurrent.CopyOnWriteArrayList<A> as)
Maps this function over a CopyOnWriteArrayList.

Parameters:
as - A CopyOnWriteArrayList to map this function over.
Returns:
A new CopyOnWriteArrayList with this function applied to each element.

mapJ

public final java.util.concurrent.ConcurrentLinkedQueue<B> mapJ(java.util.concurrent.ConcurrentLinkedQueue<A> as)
Maps this function over a ConcurrentLinkedQueue.

Parameters:
as - A ConcurrentLinkedQueue to map this function over.
Returns:
A new ConcurrentLinkedQueue with this function applied to each element.

mapJ

public final java.util.concurrent.ArrayBlockingQueue<B> mapJ(java.util.concurrent.ArrayBlockingQueue<A> as)
Maps this function over an ArrayBlockingQueue.

Parameters:
as - An ArrayBlockingQueue to map this function over.
Returns:
A new ArrayBlockingQueue with this function applied to each element.

mapJ

public final java.util.TreeSet<B> mapJ(java.util.TreeSet<A> as)
Maps this function over a TreeSet.

Parameters:
as - A TreeSet to map this function over.
Returns:
A new TreeSet with this function applied to each element.

mapJ

public final java.util.PriorityQueue<B> mapJ(java.util.PriorityQueue<A> as)
Maps this function over a PriorityQueue.

Parameters:
as - A PriorityQueue to map this function over.
Returns:
A new PriorityQueue with this function applied to each element.

mapJ

public final java.util.LinkedList<B> mapJ(java.util.LinkedList<A> as)
Maps this function over a LinkedList.

Parameters:
as - A LinkedList to map this function over.
Returns:
A new LinkedList with this function applied to each element.

mapJ

public final java.util.ArrayList<B> mapJ(java.util.ArrayList<A> as)
Maps this function over an ArrayList.

Parameters:
as - An ArrayList to map this function over.
Returns:
A new ArrayList with this function applied to each element.

Copyright 2008 - 2010 Tony Morris, Runar Bjarnason, Tom Adams, Brad Clow, Ricky Clarkson, Nick Partridge, Jason Zaugg

This software is released under an open source BSD licence.