@@ -81,27 +81,46 @@ object NonEmptyLazyList extends NonEmptyLazyListInstances {
81
81
def apply [A ](a : => A , as : A * ): NonEmptyLazyList [A ] =
82
82
create(a #:: LazyList .from(as))
83
83
84
- // allows the creation of fully lazy `NonEmptyLazyList`s by prepending to this
84
+ /**
85
+ * Wraps a `LazyList` that may or may not be empty so that individual
86
+ * elements or `NonEmptyLazyList`s can be prepended to it to construct a
87
+ * result that is guaranteed not to be empty without evaluating any elements.
88
+ */
85
89
def maybe [A ](ll : => LazyList [A ]): Maybe [A ] = new Maybe (() => ll)
86
90
91
+ /**
92
+ * Wrapper around a `LazyList` that may or may not be empty so that individual
93
+ * elements or `NonEmptyLazyList`s can be prepended to it to construct a
94
+ * result that is guaranteed not to be empty without evaluating any elements.
95
+ */
87
96
final class Maybe [A ] private [NonEmptyLazyList ] (mkLL : () => LazyList [A ]) {
88
97
// because instances of this class are created explicitly, they might be
89
98
// reused, and we don't want to re-evaluate `mkLL`
90
99
private [this ] lazy val ll = mkLL()
91
100
101
+ /** Prepends a single element, yielding a `NonEmptyLazyList`. */
92
102
def #:: [AA >: A ](elem : => AA ): NonEmptyLazyList [AA ] =
93
103
create(elem #:: ll)
104
+
105
+ /** Prepends a `LazyList`, yielding another [[Maybe ]]. */
94
106
def #::: [AA >: A ](prefix : => LazyList [AA ]): Maybe [AA ] =
95
107
new Maybe (() => prefix #::: ll)
108
+
109
+ /** Prepends a `NonEmptyLazyList`, yielding a `NonEmptyLazyList`. */
96
110
def #::: [AA >: A ](prefix : => NonEmptyLazyList [AA ])(implicit d : DummyImplicit ): NonEmptyLazyList [AA ] =
97
111
create(prefix.toLazyList #::: ll)
98
112
}
99
113
100
114
final class Deferrer [A ] private [NonEmptyLazyList ] (private val nell : () => NonEmptyLazyList [A ]) extends AnyVal {
115
+ /** Prepends a single element. */
101
116
def #:: [AA >: A ](elem : => AA ): NonEmptyLazyList [AA ] =
102
117
create(elem #:: nell().toLazyList)
118
+
119
+ /** Prepends a `LazyList`. */
103
120
def #::: [AA >: A ](prefix : => LazyList [AA ]): NonEmptyLazyList [AA ] =
104
121
create(prefix #::: nell().toLazyList)
122
+
123
+ /** Prepends a `NonEmptyLazyList`. */
105
124
def #::: [AA >: A ](prefix : => NonEmptyLazyList [AA ])(implicit d : DummyImplicit ): NonEmptyLazyList [AA ] =
106
125
create(prefix.toLazyList #::: nell().toLazyList)
107
126
}
0 commit comments