Package fj.data
Class IterableW<A>
java.lang.Object
fj.data.IterableW<A>
- All Implemented Interfaces:
Iterable<A>
A wrapper for Iterable that equips it with some useful functions.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<B> IterableW
<B> Performs function application within an iterable (applicative functor pattern).arrow()
Provides a transformation from a function to a Iterable-valued function that is equivalent to it.bind()
The first-class bind function over Iterable.Binds the given function across the wrapped Iterable with a final join.static <A,
B, C> IterableW <C> Binds the given function to the values in the given iterables with a final join.<B> B
The catamorphism for Iterables, implemented as a left fold.Takes the first 2 elements of the iterable and applies the function to them, then applies the function to the result and the third element and so on.Takes the first 2 elements of the iterable and applies the function to them, then applies the function to the result and the third element and so on.<B> B
The catamorphism for Iterables, implemented as a right fold.static <A> IterableW
<A> iterable
(A a) Returns an Iterable that completely preserves the argument.Wraps a given function's return value in a Iterable.iterator()
Returns an iterator for this iterable.join()
Returns a function that joins an Iterable of Iterables into a single Iterable.Joins an Iterable of Iterables into a single Iterable.Promotes a function of arity-2 to a function on iterables.map()
Returns a function that promotes any function so that it operates on Iterables.<B> IterableW
<B> Maps a given function across the wrapped Iterable.Performs a bind across each element of all iterables of an iterable, collecting the values in an iterable.Returns a java.util.List implementation for this iterable.toZipper()
wrap()
Provides a function that wraps the given iterable.static <A> IterableW
<A> Wraps the given iterable.<B> IterableW
<B> Zips this iterable with the given iterable of functions, applying each function in turn to the corresponding element in this iterable to produce a new iterable.Zips this iterable with the given iterable to produce a iterable of pairs.zipIndex()
Zips this iterable with the index of its element as a pair.<B,
C> Iterable <C> Zips this iterable with the given iterable using the given function to produce a new iterable.<B,
C> Iterable <C> Zips this iterable with the given iterable using the given function to produce a new iterable.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
i
-
-
Constructor Details
-
IterableW
-
-
Method Details
-
wrap
Wraps the given iterable.- Parameters:
a
- The iterable to wrap.- Returns:
- An iterable equipped with some useful functions.
-
wrap
Provides a function that wraps the given iterable.- Returns:
- A function that returns the given iterable, wrapped.
-
iterable
Returns an Iterable that completely preserves the argument. The unit function for Iterables.- Parameters:
a
- A value to preserve in an Iterable.- Returns:
- An Iterable that yields the argument when iterated over.
-
iterable
Wraps a given function's return value in a Iterable. The Kleisli arrow for Iterables.- Parameters:
f
- The function whose return value to wrap in a Iterable.- Returns:
- The equivalent function whose return value is iterable.
-
arrow
Provides a transformation from a function to a Iterable-valued function that is equivalent to it. The first-class Kleisli arrow for Iterables.- Returns:
- A transformation from a function to the equivalent Iterable-valued function.
-
bind
Binds the given function across the wrapped Iterable with a final join.- Parameters:
f
- A function to bind across the Iterable.- Returns:
- an iterable result of binding the given function over the wrapped Iterable.
-
apply
Performs function application within an iterable (applicative functor pattern).- Parameters:
f
- The iterable function to apply.- Returns:
- A new iterable after applying the given iterable function to the wrapped iterable.
-
bind
Binds the given function to the values in the given iterables with a final join.- Parameters:
a
- A given iterable to bind the given function with.b
- A given iterable to bind the given function with.f
- The function to apply to the values in the given iterables.- Returns:
- A new iterable after performing the map, then final join.
-
liftM2
Promotes a function of arity-2 to a function on iterables.- Parameters:
f
- The function to promote.- Returns:
- A function of arity-2 promoted to map over iterables.
-
sequence
Performs a bind across each element of all iterables of an iterable, collecting the values in an iterable. This implementation is strict and requires O(n) stack space.- Parameters:
as
- The iterable of iterables to transform.- Returns:
- A iterable of iterables containing the results of the bind operations across all given iterables.
-
bind
The first-class bind function over Iterable. Returns a function that binds a given function across a given iterable.- Returns:
- a function that binds a given function across a given iterable.
-
join
Joins an Iterable of Iterables into a single Iterable.- Parameters:
as
- An Iterable of Iterables to join.- Returns:
- the joined Iterable.
-
join
Returns a function that joins an Iterable of Iterables into a single Iterable.- Returns:
- a function that joins an Iterable of Iterables into a single Iterable.
-
map
Maps a given function across the wrapped Iterable.- Parameters:
f
- A function to map across the wrapped Iterable.- Returns:
- An Iterable of the results of mapping the given function across the wrapped Iterable.
-
map
Returns a function that promotes any function so that it operates on Iterables.- Returns:
- a function that promotes any function so that it operates on Iterables.
-
foldLeft
The catamorphism for Iterables, implemented as a left fold.- Parameters:
f
- The function with which to fold the wrapped iterable.z
- The base case value of the destination type, applied first (leftmost) to the fold.- Returns:
- The result of the catamorphism.
-
foldLeft1
Takes the first 2 elements of the iterable and applies the function to them, then applies the function to the result and the third element and so on.- Parameters:
f
- The function to apply on each element of the iterable.- Returns:
- The final result after the left-fold reduction.
-
foldLeft1
Takes the first 2 elements of the iterable and applies the function to them, then applies the function to the result and the third element and so on.- Parameters:
f
- The function to apply on each element of the iterable.- Returns:
- The final result after the left-fold reduction.
-
foldRight
The catamorphism for Iterables, implemented as a right fold.- Parameters:
f
- The function with which to fold the wrapped iterable.z
- The base case value of the destination type, applied last (rightmost) to the fold.- Returns:
- The result of the catamorphism.
-
iterator
Returns an iterator for this iterable. -
zapp
Zips this iterable with the given iterable of functions, applying each function in turn to the corresponding element in this iterable to produce a new iterable. The iteration is normalised so that it ends when one of the iterators is exhausted.- Parameters:
fs
- The iterable of functions to apply to this iterable.- Returns:
- A new iterable with the results of applying the functions to this iterable.
-
zipWith
Zips this iterable with the given iterable using the given function to produce a new iterable. If this iterable and the given iterable have different lengths, then the longer iterable is normalised so this function never fails.- Parameters:
bs
- The iterable to zip this iterable with.f
- The function to zip this iterable and the given iterable with.- Returns:
- A new iterable with a length the same as the shortest of this iterable and the given iterable.
-
zipWith
Zips this iterable with the given iterable using the given function to produce a new iterable. If this iterable and the given iterable have different lengths, then the longer iterable is normalised so this function never fails.- Parameters:
bs
- The iterable to zip this iterable with.f
- The function to zip this iterable and the given iterable with.- Returns:
- A new iterable with a length the same as the shortest of this iterable and the given iterable.
-
zip
Zips this iterable with the given iterable to produce a iterable of pairs. If this iterable and the given iterable have different lengths, then the longer iterable is normalised so this function never fails.- Parameters:
bs
- The iterable to zip this iterable with.- Returns:
- A new iterable with a length the same as the shortest of this iterable and the given iterable.
-
zipIndex
Zips this iterable with the index of its element as a pair.- Returns:
- A new iterable with the same length as this iterable.
-
toStandardList
Returns a java.util.List implementation for this iterable. The returned list cannot be modified.- Returns:
- An immutable implementation of java.util.List for this iterable.
-
toZipper
-