Module: LazyList::ModuleFunctions
Overview
This module contains module functions, that are added to LazyList and it’s instances.
Instance Method Summary collapse
-
#delay(&block) ⇒ Object
Delay the value of block to a Promise.
-
#force(obj) ⇒ Object
Force the delayed obj to evaluate to its value.
-
#mix(*lists) ⇒ Object
Returns a LazyList, that consists of the mixed elements of the lists _lists without any special order.
Instance Method Details
#delay(&block) ⇒ Object
Delay the value of block to a Promise.
234 235 236 |
# File 'lib/lazylist.rb', line 234 def delay(&block) MemoPromise.new(&block) end |
#force(obj) ⇒ Object
Force the delayed obj to evaluate to its value.
239 240 241 242 243 244 245 246 |
# File 'lib/lazylist.rb', line 239 def force(obj) case obj when Promise force obj.__value__ else obj end end |
#mix(*lists) ⇒ Object
Returns a LazyList, that consists of the mixed elements of the lists _lists without any special order.
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/lazylist.rb', line 250 def mix(*lists) return empty if lists.empty? first = lists.shift if lists.empty? first elsif first.empty? mix(*lists) else LazyList.new(first.head) do t = first.tail lists = lists.push t unless t.empty? mix(*lists) end end end |