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
Copy file name to clipboardExpand all lines: README.md
+52-1Lines changed: 52 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,8 @@ Functional patterns for Java 8
19
19
-[Monads](#monads)
20
20
-[Traversables](#traversables)
21
21
-[ADTs](#adts)
22
-
-[HLists](#hlists)
22
+
-[Maybe](#maybe)
23
+
-[HList](#hlist)
23
24
-[Tuples](#tuples)
24
25
-[HMaps](#hmaps)
25
26
-[CoProducts](#coproducts)
@@ -455,6 +456,56 @@ As always, there are [some laws](https://hackage.haskell.org/package/base-4.9.1.
455
456
456
457
Lambda also supports a few first-class [algebraic data types](https://www.wikiwand.com/en/Algebraic_data_type).
457
458
459
+
### <a name="maybe">Maybe</a>
460
+
461
+
`Maybe` is the _lambda_ analog to `java.util.Optional`.It behaves in much of the same way as `j.u.Optional`, except that it quite intentionally does not support the inherently unsafe `j.u.Optional#get`.
***Note***: One compatibility difference between `j.u.Optional` and `Maybe` is how `map`/`fmap` behave regarding functions that return `null`: `j.u.Optional` re-wraps `null` results from `map` operations in another `j.u.Optional`, whereas `Maybe` considers this to be an error, and throws an exception. The reason `Maybe` throws in this case is because `fmap` is not an operation to be called speculatively, and so any function that returns `null` in the context of an `fmap` operation is considered to be erroneous. Instead of calling `fmap` with a function that might return `null`, the function result should be wrapped in a `Maybe` and `flatMap` should be used, as illustrated in the following example:
HLists are type-safe heterogeneous lists, meaning they can store elements of different types in the same list while facilitating certain type-safe interactions.
0 commit comments