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 P1<A>

java.lang.Object
  extended by fj.P1<A>
Direct Known Subclasses:
$

public abstract class P1<A>
extends Object

A product-1. Also, the identity monad.


Constructor Summary
P1()
           
 
Method Summary
static
<A> F<P1<A>,A>
__1()
          Returns a function that returns the first element of a product.
abstract  A _1()
          Access the first element of the product.
static
<A,B> P1<B>
apply(P1<A> ca, P1<F<A,B>> cf)
          Performs function application within a P1 (applicative functor pattern).
static
<A,B> P1<B>
bind(P1<A> a, F<A,P1<B>> f)
          Binds the given function to the value in a product-1 with a final join.
static
<A,B,C> P1<C>
bind(P1<A> ca, P1<B> cb, F<A,F<B,C>> f)
          Binds the given function to the values in the given P1s with a final join.
<B> F<B,A>
constant()
          Returns a constant function that always uses this value.
static
<A,B> F<A,P1<B>>
curry(F<A,B> f)
          Promotes the given function so that it returns its value in a P1.
static
<A,B> F<P1<A>,P1<B>>
fmap(F<A,B> f)
          Promote any function to a transformation between P1s.
static
<A> P1<A>
join(P1<P1<A>> a)
          Joins a P1 of a P1 with a bind operation.
static
<A,B,C> F<P1<A>,F<P1<B>,P1<C>>>
liftM2(F<A,F<B,C>> f)
          Promotes a function of arity-2 to a function on P1s.
<X> P1<X>
map(F<A,X> f)
          Map the element of the product.
 P1<A> memo()
          Provides a memoising P1 that remembers its value.
static
<A> P1<Array<A>>
sequence(Array<P1<A>> as)
          Turns an array of P1s into a single P1 of an array.
static
<A> P1<List<A>>
sequence(List<P1<A>> as)
          Turns a List of P1s into a single P1 of a List.
static
<A> P1<Stream<A>>
sequence(Stream<P1<A>> as)
          Turns a stream of P1s into a single P1 of a stream.
static
<A> F<List<P1<A>>,P1<List<A>>>
sequenceList()
          A first-class version of the sequence method for lists of P1s.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

P1

public P1()
Method Detail

_1

public abstract A _1()
Access the first element of the product.

Returns:
The first element of the product.

map

public <X> P1<X> map(F<A,X> f)
Map the element of the product.

Parameters:
f - The function to map with.
Returns:
A product with the given function applied.

__1

public static <A> F<P1<A>,A> __1()
Returns a function that returns the first element of a product.

Returns:
A function that returns the first element of a product.

fmap

public static <A,B> F<P1<A>,P1<B>> fmap(F<A,B> f)
Promote any function to a transformation between P1s.

Parameters:
f - A function to promote to a transformation between P1s.
Returns:
A function promoted to operate on P1s.

bind

public static <A,B> P1<B> bind(P1<A> a,
                               F<A,P1<B>> f)
Binds the given function to the value in a product-1 with a final join.

Parameters:
a - A value in a product-1 to which to apply a function.
f - A function to apply to the value in a product-1.
Returns:
The result of applying the given function to the value of given product-1.

curry

public static <A,B> F<A,P1<B>> curry(F<A,B> f)
Promotes the given function so that it returns its value in a P1.

Parameters:
f - A function to have its result wrapped in a P1.
Returns:
A function whose result is wrapped in a P1.

apply

public static <A,B> P1<B> apply(P1<A> ca,
                                P1<F<A,B>> cf)
Performs function application within a P1 (applicative functor pattern).

Parameters:
ca - The P1 to which to apply a function.
cf - The P1 function to apply.
Returns:
A new P1 after applying the given P1 function to the first argument.

bind

public static <A,B,C> P1<C> bind(P1<A> ca,
                                 P1<B> cb,
                                 F<A,F<B,C>> f)
Binds the given function to the values in the given P1s with a final join.

Parameters:
ca - A given P1 to bind the given function with.
cb - A given P1 to bind the given function with.
f - The function to apply to the values in the given P1s.
Returns:
A new P1 after performing the map, then final join.

join

public static <A> P1<A> join(P1<P1<A>> a)
Joins a P1 of a P1 with a bind operation.

Parameters:
a - The P1 of a P1 to join.
Returns:
A new P1 that is the join of the given P1.

liftM2

public static <A,B,C> F<P1<A>,F<P1<B>,P1<C>>> liftM2(F<A,F<B,C>> f)
Promotes a function of arity-2 to a function on P1s.

Parameters:
f - The function to promote.
Returns:
A function of arity-2 promoted to map over P1s.

sequence

public static <A> P1<List<A>> sequence(List<P1<A>> as)
Turns a List of P1s into a single P1 of a List.

Parameters:
as - The list of P1s to transform.
Returns:
A single P1 for the given List.

sequenceList

public static <A> F<List<P1<A>>,P1<List<A>>> sequenceList()
A first-class version of the sequence method for lists of P1s.

Returns:
A function from a List of P1s to a single P1 of a List.

sequence

public static <A> P1<Stream<A>> sequence(Stream<P1<A>> as)
Turns a stream of P1s into a single P1 of a stream.

Parameters:
as - The stream of P1s to transform.
Returns:
A single P1 for the given stream.

sequence

public static <A> P1<Array<A>> sequence(Array<P1<A>> as)
Turns an array of P1s into a single P1 of an array.

Parameters:
as - The array of P1s to transform.
Returns:
A single P1 for the given array.

memo

public P1<A> memo()
Provides a memoising P1 that remembers its value.

Returns:
A P1 that calls this P1 once and remembers the value for subsequent calls.

constant

public <B> F<B,A> constant()
Returns a constant function that always uses this value.

Returns:
A constant function that always uses this value.

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.