Copyright 2008 - 2009 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 FW<A,B>

java.lang.Object
  extended by fj.FW<A,B>
All Implemented Interfaces:
F<A,B>

public final class FW<A,B>
extends Object
implements F<A,B>

A wrapper for functions of arity 1, that decorates them with higher-order functions.


Method Summary
static
<A,B> FW<F<A,B>,FW<A,B>>
$()
          First-class constructor for FW.
static
<A,B> FW<A,B>
$(F<A,B> f)
          Wraps the given function, decorating it with higher-order functions.
<C> FW<F<B,C>,F<A,C>>
andThen_()
          First-class composition flipped.
<C> FW<A,C>
andThen(F<B,C> g)
          Function composition flipped.
<C> FW<F<A,F<B,C>>,F<A,C>>
apply()
          First-class function application in an environment.
<C> FW<A,C>
apply(F<A,F<B,C>> g)
          Function application in an environment (Applicative Functor).
 FW<A,Array<B>> array()
          Promotes this function so that it returns its result in an Array.
<C> FW<F<B,F<A,C>>,F<A,C>>
bind()
          First-class function binding.
<C> FW<A,C>
bind(F<B,F<A,C>> g)
          Binds a given function across this function (Reader Monad).
 FW<Actor<B>,Actor<A>> comapActor()
          Returns a function that comaps over a given actor.
 FW<Equal<B>,Equal<A>> comapEqual()
          Promotes this function to map over an Equal as a contravariant functor.
 FW<Hash<B>,Hash<A>> comapHash()
          Promotes this function to map over a Hash as a contravariant functor.
 FW<Show<B>,Show<A>> comapShow()
          Promotes this function to map over a Show as a contravariant functor.
<C> FW<A,Either<B,C>>
eitherLeft()
          Promotes this function so that it returns its result on the left side of an Either.
<C> FW<A,Either<C,B>>
eitherRight()
          Promotes this function so that it returns its result on the right side of an Either.
 B f(A a)
          Function application
<C> FW<A,Validation<B,C>>
fail()
          Promotes this function so that it returns its result on the failure side of a Validation.
 FW<Tree<A>,B> foldMapTree(Monoid<B> m)
          Returns a function that maps this function over a tree and folds it with the given monoid.
 FW<A,IterableW<B>> iterable()
          Promotes this function to return its value in an Iterable.
 FW<A,P1<B>> lazy()
          Promotes this function so that it returns its result in a product-1.
 FW<A,List<B>> list()
          Promotes this function so that it returns its result in a List.
 ArrayBlockingQueue<B> map(ArrayBlockingQueue<A> as)
          Maps this function over an ArrayBlockingQueue.
 ArrayList<B> map(ArrayList<A> as)
          Maps this function over an ArrayList.
 ConcurrentLinkedQueue<B> map(ConcurrentLinkedQueue<A> as)
          Maps this function over a ConcurrentLinkedQueue.
 CopyOnWriteArrayList<B> map(CopyOnWriteArrayList<A> as)
          Maps this function over a CopyOnWriteArrayList.
 CopyOnWriteArraySet<B> map(CopyOnWriteArraySet<A> as)
          Maps this function over a CopyOnWriteArraySet.
 LinkedBlockingQueue<B> map(LinkedBlockingQueue<A> as)
          Maps this function over a LinkedBlockingQueue.
 LinkedList<B> map(LinkedList<A> as)
          Maps this function over a LinkedList.
 PriorityBlockingQueue<B> map(PriorityBlockingQueue<A> as)
          Maps this function over a PriorityBlockingQueue.
 PriorityQueue<B> map(PriorityQueue<A> as)
          Maps this function over a PriorityQueue.
 SynchronousQueue<B> map(SynchronousQueue<A> as)
          Maps this function over a SynchronousQueue.
 TreeSet<B> map(TreeSet<A> as)
          Maps this function over a TreeSet.
 FW<Array<A>,Array<B>> mapArray()
          Promotes this function to map over a Stream.
 FW<P2<A,A>,P2<B,B>> mapBoth()
          Promotes this function to map over both elements of a pair.
<X> FW<Validation<A,X>,Validation<B,X>>
mapFail()
          Promotes this function to map over the failure side of a Validation.
<C> FW<P2<A,C>,P2<B,C>>
mapFst()
          Promotes this function to map over the first element of a pair.
 FW<Iterable<A>,IterableW<B>> mapIterable()
          Promotes this function to map over Iterables.
<X> FW<Either<A,X>,Either<B,X>>
mapLeft()
          Promotes this function to map over the left side of an Either.
 FW<List<A>,List<B>> mapList()
          Promotes this function to map over a List.
 FW<NonEmptyList<A>,NonEmptyList<B>> mapNel()
          Promotes this function to map over a NonEmptyList.
 FW<Option<A>,Option<B>> mapOption()
          Promotes this function to map over an optional value.
 FW<P1<A>,P1<B>> mapP1()
          Promotes this function to map over a product-1.
 FW<Promise<A>,Promise<B>> mapPromise()
          Promotes this function to map over a Promise.
<X> FW<Either<X,A>,Either<X,B>>
mapRight()
          Promotes this function to map over the right side of an Either.
 FW<Set<A>,Set<B>> mapSet(Ord<B> o)
          Promotes this function to map over a Set.
<C> FW<P2<C,A>,P2<C,B>>
mapSnd()
          Promotes this function to map over the second element of a pair.
 FW<Stream<A>,Stream<B>> mapStream()
          Promotes this function to map over a Stream.
<X> FW<Validation<X,A>,Validation<X,B>>
mapSuccess()
          Promotes this function to map over the success side of a Validation.
 FW<Tree<A>,Tree<B>> mapTree()
          Promotes this function to map over a Tree.
 FW<TreeZipper<A>,TreeZipper<B>> mapTreeZipper()
          Promotes this function to map over a TreeZipper.
 FW<Zipper<A>,Zipper<B>> mapZipper()
          Promotes this function to map over a Zipper.
 FW<A,NonEmptyList<B>> nel()
          Promotes this function to return its value in a NonEmptyList.
<C> FW<F<C,A>,F<C,B>>
o_()
          First-class function composition
<C> FW<C,B>
o(F<C,A> g)
          Function composition
<C> FW<F<B,F<B,C>>,F<A,F<A,C>>>
on()
          First-class composition with a function of arity-2
<C> FW<A,F<A,C>>
on(F<B,F<B,C>> g)
          Applies this function over the arguments of another function.
 FW<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.
 FW<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.
 FW<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.
 FW<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.
 FW<A,Option<B>> option()
          Promotes this function so that it returns its result in an Option.
 FW<A,Promise<B>> promise(Strategy<Unit> s)
          Promotes this function to a concurrent function that returns a Promise of a value.
 FW<A,Set<B>> set(Ord<B> o)
          Promotes this function to return its value in a Set.
 FW<A,Stream<B>> stream()
          Promotes this function so that it returns its result in a Stream.
<C> FW<A,Validation<C,B>>
success()
          Promotes this function so that it returns its result on the success side of an Validation.
 FW<A,Tree<B>> tree()
          Promotes this function to return its value in a Tree.
 FW<A,TreeZipper<B>> treeZipper()
          Promotes this function to return its value in a TreeZipper.
 FW<? super A,? extends B> vary()
          Simultaneously covaries and contravaries a function.
 FW<A,Zipper<B>> zipper()
          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
 

Method Detail

$

public static <A,B> FW<A,B> $(F<A,B> f)
Wraps the given function, decorating it with higher-order functions.

Parameters:
f - A function to wrap.
Returns:
The given function, wrapped.

$

public static <A,B> FW<F<A,B>,FW<A,B>> $()
First-class constructor for FW.

Returns:
A function that wraps a given function.

f

public B f(A a)
Function application

Specified by:
f in interface F<A,B>
Parameters:
a - The A to transform.
Returns:
The result of the transformation.

o

public <C> FW<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 <C> FW<F<C,A>,F<C,B>> o_()
First-class function composition

Returns:
A function that composes this function with another.

andThen

public <C> FW<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 <C> FW<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.

vary

public FW<? super A,? extends B> vary()
Simultaneously covaries and contravaries a function.

Returns:
A co- and contravariant function that invokes this function on its argument.

bind

public <C> FW<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 <C> FW<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 <C> FW<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 <C> FW<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 <C> FW<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 <C> FW<F<B,F<B,C>>,F<A,F<A,C>>> on()
First-class composition with a function of arity-2

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

lazy

public FW<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 FW<P1<A>,P1<B>> mapP1()
Promotes this function to map over a product-1.

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

option

public FW<A,Option<B>> option()
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 FW<Option<A>,Option<B>> mapOption()
Promotes this function to map over an optional value.

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

list

public FW<A,List<B>> list()
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 FW<List<A>,List<B>> mapList()
Promotes this function to map over a List.

Returns:
This function promoted to map over a List.

stream

public FW<A,Stream<B>> stream()
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 FW<Stream<A>,Stream<B>> mapStream()
Promotes this function to map over a Stream.

Returns:
This function promoted to map over a Stream.

array

public FW<A,Array<B>> array()
Promotes this function so that it returns its result in an Array. Kleisli arrow for Array.

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

mapArray

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

Returns:
This function promoted to map over a Stream.

comapActor

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

Returns:
A function that comaps over a given actor.

promise

public FW<A,Promise<B>> promise(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 FW<Promise<A>,Promise<B>> mapPromise()
Promotes this function to map over a Promise.

Returns:
This function promoted to map over Promises.

eitherLeft

public <C> FW<A,Either<B,C>> eitherLeft()
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.

eitherRight

public <C> FW<A,Either<C,B>> eitherRight()
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 <X> FW<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 <X> FW<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 FW<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 FW<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.

iterable

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

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

mapIterable

public FW<Iterable<A>,IterableW<B>> mapIterable()
Promotes this function to map over Iterables.

Returns:
This function promoted to map over Iterables.

nel

public FW<A,NonEmptyList<B>> nel()
Promotes this function to return its value in a NonEmptyList.

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

mapNel

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

Returns:
This function promoted to map over a NonEmptyList.

set

public FW<A,Set<B>> set(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 FW<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.

tree

public FW<A,Tree<B>> tree()
Promotes this function to return its value in a Tree.

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

mapTree

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

Returns:
This function promoted to map over a Tree.

foldMapTree

public FW<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.

treeZipper

public FW<A,TreeZipper<B>> treeZipper()
Promotes this function to return its value in a TreeZipper.

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

mapTreeZipper

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

Returns:
This function promoted to map over a TreeZipper.

fail

public <C> FW<A,Validation<B,C>> fail()
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.

success

public <C> FW<A,Validation<C,B>> success()
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 <X> FW<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 <X> FW<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 FW<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 FW<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.

zipper

public FW<A,Zipper<B>> zipper()
Promotes this function to return its value in a Zipper.

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

mapZipper

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

Returns:
This function promoted to map over a Zipper.

comapEqual

public FW<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 FW<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 FW<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 <C> FW<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 <C> FW<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 FW<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.

map

public SynchronousQueue<B> map(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.

map

public PriorityBlockingQueue<B> map(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.

map

public LinkedBlockingQueue<B> map(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.

map

public CopyOnWriteArraySet<B> map(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.

map

public CopyOnWriteArrayList<B> map(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.

map

public ConcurrentLinkedQueue<B> map(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.

map

public ArrayBlockingQueue<B> map(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.

map

public TreeSet<B> map(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.

map

public PriorityQueue<B> map(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.

map

public LinkedList<B> map(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.

map

public ArrayList<B> map(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 - 2009 Tony Morris, Runar Bjarnason, Tom Adams, Brad Clow, Ricky Clarkson, Nick Partridge, Jason Zaugg

This software is released under an open source BSD licence.