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.data.vector
Class V2<A>

java.lang.Object
  extended by fj.data.vector.V2<A>
All Implemented Interfaces:
Iterable<A>

public final class V2<A>
extends Object
implements Iterable<A>

A vector-2.


Method Summary
static
<A> F<V2<A>,A>
__1()
          A first-class function to get the first element of a vector.
static
<A> F<V2<A>,A>
__2()
          A first-class function to get the second element of a vector.
 A _1()
          Returns the first element of this vector.
 A _2()
          Returns the second element of this vector.
<B> V2<B>
apply(V2<F<A,B>> vf)
          Performs function application within a vector (applicative functor pattern).
 P1<A> head()
          Return the first element of this vector as a product-1.
 Iterator<A> iterator()
          Returns an iterator for the elements of this vector.
<B> V2<B>
map(F<A,B> f)
          Maps the given function across this vector.
static
<A> F<V2<A>,P2<A,A>>
p_()
          Returns a function that transforms a vector-2 to the equivalent product-2.
 P2<A,A> p()
          Returns a homogeneous product-2 equivalent to this vector.
static
<A> V2<A>
p(P2<A,A> p)
          Creates a vector-2 from a homogeneous product-2.
 Array<A> toArray()
          Returns an array with the elements of this vector.
 NonEmptyList<A> toNonEmptyList()
          Returns a nonempty list with the elements of this vector.
static
<A> F<V2<A>,Stream<A>>
toStream_()
          Returns a function that transforms a vector-2 to a stream of its elements.
 Stream<A> toStream()
          Returns a stream of the elements of this vector.
 V2<V2<A>> vzip(V2<A> bs)
          Zips this vector with the given vector to produce a vector of vectors.
<B> V2<P2<A,B>>
zip(V2<B> bs)
          Zips this vector with the given vector to produce a vector of pairs.
<B,C> V2<C>
zipWith(F<A,F<B,C>> f, V2<B> bs)
          Zips this vector with the given vector using the given function to produce a new vector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

p

public static <A> V2<A> p(P2<A,A> p)
Creates a vector-2 from a homogeneous product-2.

Parameters:
p - The product-2 from which to create a vector.
Returns:
A new vector-2.

_1

public A _1()
Returns the first element of this vector.

Returns:
the first element of this vector.

_2

public A _2()
Returns the second element of this vector.

Returns:
the second element of this vector.

__1

public static <A> F<V2<A>,A> __1()
A first-class function to get the first element of a vector.

Returns:
a function that gets the first element of a given vector.

__2

public static <A> F<V2<A>,A> __2()
A first-class function to get the second element of a vector.

Returns:
a function that gets the second element of a given vector.

iterator

public Iterator<A> iterator()
Returns an iterator for the elements of this vector.

Specified by:
iterator in interface Iterable<A>
Returns:
an iterator for the elements of this vector.

p

public P2<A,A> p()
Returns a homogeneous product-2 equivalent to this vector.

Returns:
a homogeneous product-2 equivalent to this vector.

toNonEmptyList

public NonEmptyList<A> toNonEmptyList()
Returns a nonempty list with the elements of this vector.

Returns:
a nonempty list with the elements of this vector.

toStream

public Stream<A> toStream()
Returns a stream of the elements of this vector.

Returns:
a stream of the elements of this vector.

toStream_

public static <A> F<V2<A>,Stream<A>> toStream_()
Returns a function that transforms a vector-2 to a stream of its elements.

Returns:
a function that transforms a vector-2 to a stream of its elements.

p_

public static <A> F<V2<A>,P2<A,A>> p_()
Returns a function that transforms a vector-2 to the equivalent product-2.

Returns:
a function that transforms a vector-2 to the equivalent product-2.

toArray

public Array<A> toArray()
Returns an array with the elements of this vector.

Returns:
an array with the elements of this vector.

map

public <B> V2<B> map(F<A,B> f)
Maps the given function across this vector.

Parameters:
f - The function to map across this vector.
Returns:
A new vector after the given function has been applied to each element.

apply

public <B> V2<B> apply(V2<F<A,B>> vf)
Performs function application within a vector (applicative functor pattern).

Parameters:
vf - The vector of functions to apply.
Returns:
A new vector after zipping the given vector of functions over this vector.

zipWith

public <B,C> V2<C> zipWith(F<A,F<B,C>> f,
                           V2<B> bs)
Zips this vector with the given vector using the given function to produce a new vector.

Parameters:
bs - The vector to zip this vector with.
f - The function to zip this vector and the given vector with.
Returns:
A new vector with the results of the function.

zip

public <B> V2<P2<A,B>> zip(V2<B> bs)
Zips this vector with the given vector to produce a vector of pairs.

Parameters:
bs - The vector to zip this vector with.
Returns:
A new vector with a length the same as the shortest of this vector and the given vector.

vzip

public V2<V2<A>> vzip(V2<A> bs)
Zips this vector with the given vector to produce a vector of vectors.

Parameters:
bs - The vector to zip this vector with.
Returns:
A new vector of vectors.

head

public P1<A> head()
Return the first element of this vector as a product-1.

Returns:
the first element of this vector as a product-1.

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.