You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>Lambda was born out of a desire to use some of the same canonical functions (e.g. <code>unfoldr</code>, <code>takeWhile</code>, <code>zipWith</code>) and functional patterns (e.g. <code>Functor</code> and friends) that are idiomatic in other languages and make them available for Java.</p>
43
76
@@ -56,7 +89,8 @@ <h2>
56
89
<p>Although the library is currently (very) small, these values should always be the driving forces behind future growth.</p>
<p>First, the obligatory <code>map</code>/<code>filter</code>/<code>reduce</code> example:</p>
79
114
@@ -139,12 +174,14 @@ <h2>
139
174
<p>Check out the <ahref="https://github.com/palatable/lambda/tree/master/src/test/java/com/jnape/palatable/lambda/functions/builtin">tests</a> or <ahref="http://palatable.github.io/lambda/javadoc/">javadoc</a> for more examples.</p>
<p>In addition to the functions above, lambda also supports a few first-class <ahref="https://www.wikiwand.com/en/Algebraic_data_type">algebraic data types</a>.</p>
<p>HLists are type-safe heterogeneous lists, meaning they can store elements of different types in the same list while facilitating certain type-safe interactions.</p>
<p>One of the primary downsides to using <code>HList</code>s in Java is how quickly the type signature grows.</p>
165
203
@@ -197,7 +235,8 @@ <h4>
197
235
<spanclass="pl-smi">System</span><spanclass="pl-k">.</span>out<spanclass="pl-k">.</span>println(mappedTuple3<spanclass="pl-k">.</span>_3()); <spanclass="pl-c">// prints 2</span></pre></div>
<p>HMaps are type-safe heterogeneous maps, meaning they can store mappings to different value types in the same map; however, whereas HLists encode value types in their type signatures, HMaps rely on the keys to encode the value type that they point to. </p>
<p>Binary tagged unions are represented as <code>Either<L, R></code>s, which resolve to one of two possible values: a <code>Left</code> value wrapping an <code>L</code>, or a <code>Right</code> value wrapping an <code>R</code> (typically an exceptional value or a successful value, respectively).</p>
217
257
@@ -229,7 +269,16 @@ <h3>
229
269
<p>Check out the tests for <ahref="https://github.com/palatable/lambda/blob/master/src/test/java/com/jnape/palatable/lambda/adt/EitherTest.java">more examples</a> of ways to interact with <code>Either</code>.</p>
<p>Wherever possible, <em>lambda</em> maintains interface compatibility with similar, familiar core Java types. Some examples of where this works well is with both <code>Fn1</code> and <code>Predicate</code>, which extend <code>j.u.f.Function</code> and <code>j.u.f.Predicate</code>, respectively. In these examples, they also override any implemented methods to return their <em>lambda</em>-specific counterparts (<code>Fn1.compose</code> returning <code>Fn1</code> instead of <code>j.u.f.Function</code> as an example).</p>
276
+
277
+
<p>Unfortunately, due to Java's type hierarchy and inheritance inconsistencies, this is not always possible. One surprising example of this is how <code>Fn1</code> extends <code>j.u.f.Function</code>, but <code>Fn2</code> does not extend <code>j.u.f.BiFunction</code>. This is because <code>j.u.f.BiFunction</code> itself does not extend <code>j.u.f.Function</code>, but it does define methods that collide with <code>j.u.f.Function</code>. For this reason, both <code>Fn1</code> and <code>Fn2</code> cannot extend their Java counterparts without sacrificing their own inheritance hierarchy. These types of asymmetries are, unfortunately, not uncommon; however, wherever these situations arise, measures are taken to attempt to ease the transition in and out of core Java types (in the case of <code>Fn2</code>, a supplemental <code>#toBiFunction</code> method is added). I do not take these inconveniences for granted, and I'm regularly looking for ways to minimize the negative impact of this as much as possible. Suggestions and use cases that highlight particular pain points here are particularly appreciated.</p>
<p><em>lambda</em> is part of <ahref="http://www.github.com/palatable">palatable</a>, which is distributed under <ahref="http://choosealicense.com/licenses/mit/">The MIT License</a>.</p>
0 commit comments