@@ -5,9 +5,9 @@ function reverse(list) {
55 return [ ...list ] . reverse ( ) ;
66}
77
8- async function foreach ( fun , list ) {
8+ function * foreach ( fun , list ) {
99 for ( const x of list ) {
10- await fun ( x ) ;
10+ yield * fun ( x ) ;
1111 }
1212
1313 return Symbol . for ( 'ok' ) ;
@@ -35,17 +35,17 @@ function flatten(deepList, tail = []) {
3535 return val . concat ( tail ) ;
3636}
3737
38- async function foldl ( fun , acc0 , list ) {
38+ function * foldl ( fun , acc0 , list ) {
3939 let acc = acc0 ;
4040
4141 for ( const value of list ) {
42- acc = await fun ( value , acc ) ;
42+ acc = yield * fun ( value , acc ) ;
4343 }
4444
4545 return acc ;
4646}
4747
48- async function foldr ( fun , acc0 , list ) {
48+ function foldr ( fun , acc0 , list ) {
4949 return foldl ( fun , acc0 , reverse ( list ) ) ;
5050}
5151
@@ -126,18 +126,22 @@ function keytake(key, n, tupleList) {
126126 const result = keyfind ( key , n , tupleList ) ;
127127
128128 if ( result !== false ) {
129- return new ErlangTypes . Tuple ( result . get ( n - 1 ) , result , keydelete ( key , n , tupleList ) ) ;
129+ return new ErlangTypes . Tuple (
130+ result . get ( n - 1 ) ,
131+ result ,
132+ keydelete ( key , n , tupleList )
133+ ) ;
130134 }
131135
132136 return false ;
133137}
134138
135- async function mapfoldl ( fun , acc0 , list1 ) {
139+ function * mapfoldl ( fun , acc0 , list1 ) {
136140 const listResult = [ ] ;
137141 let accResult = acc0 ;
138142
139143 for ( const item of list1 ) {
140- const tuple = await fun ( item , accResult ) ;
144+ const tuple = yield * fun ( item , accResult ) ;
141145 listResult . push ( tuple . get ( 0 ) ) ;
142146 accResult = tuple . get ( 1 ) ;
143147 }
@@ -149,22 +153,22 @@ function concat(things) {
149153 return things . map ( v => v . toString ( ) ) . join ( ) ;
150154}
151155
152- async function map ( fun , list ) {
156+ function * map ( fun , list ) {
153157 const reList = [ ] ;
154158
155159 for ( const value of list ) {
156- const result = await fun ( value ) ;
160+ const result = yield * fun ( value ) ;
157161 reList . push ( result ) ;
158162 }
159163
160164 return reList ;
161165}
162166
163- async function filter ( pred , list1 ) {
167+ function * filter ( pred , list1 ) {
164168 const reList = [ ] ;
165169
166170 for ( const value of list1 ) {
167- const result = await pred ( value ) ;
171+ const result = yield * pred ( value ) ;
168172 if ( result === true ) {
169173 reList . push ( value ) ;
170174 }
@@ -173,11 +177,11 @@ async function filter(pred, list1) {
173177 return reList ;
174178}
175179
176- async function filtermap ( fun , list1 ) {
180+ function * filtermap ( fun , list1 ) {
177181 const list2 = [ ] ;
178182
179183 for ( const item of list1 ) {
180- const value = await fun ( item ) ;
184+ const value = yield * fun ( item ) ;
181185
182186 if ( value === true ) {
183187 list2 . push ( item ) ;
@@ -199,35 +203,35 @@ function member(elem, list) {
199203 return false ;
200204}
201205
202- async function all ( pred , list ) {
206+ function * all ( pred , list ) {
203207 for ( const item of list ) {
204- if ( ( await pred ( item ) ) === false ) {
208+ if ( ( yield * pred ( item ) ) === false ) {
205209 return false ;
206210 }
207211 }
208212
209213 return true ;
210214}
211215
212- async function any ( pred , list ) {
216+ function * any ( pred , list ) {
213217 for ( const item of list ) {
214- if ( ( await pred ( item ) ) === true ) {
218+ if ( ( yield * pred ( item ) ) === true ) {
215219 return true ;
216220 }
217221 }
218222
219223 return false ;
220224}
221225
222- async function splitwith ( pred , list ) {
226+ function * splitwith ( pred , list ) {
223227 let switchToList2 = false ;
224228 const list1 = [ ] ;
225229 const list2 = [ ] ;
226230
227231 for ( const item of list ) {
228232 if ( switchToList2 === true ) {
229233 list2 . push ( item ) ;
230- } else if ( ( await pred ( item ) ) === true ) {
234+ } else if ( ( yield * pred ( item ) ) === true ) {
231235 list1 . push ( item ) ;
232236 } else {
233237 switchToList2 = true ;
@@ -238,7 +242,7 @@ async function splitwith(pred, list) {
238242 return new ErlangTypes . Tuple ( list1 , list2 ) ;
239243}
240244
241- async function sort ( ...args ) {
245+ function * sort ( ...args ) {
242246 if ( args . length === 1 ) {
243247 const list2 = [ ...args [ 0 ] ] ;
244248 return list2 . sort ( ) ;
@@ -247,8 +251,8 @@ async function sort(...args) {
247251 const fun = args [ 0 ] ;
248252 const list2 = [ ...args [ 1 ] ] ;
249253
250- const result = list2 . sort ( async ( a , b ) => {
251- const sortResult = await fun ( a , b ) ;
254+ const result = list2 . sort ( function * ( a , b ) {
255+ const sortResult = yield * fun ( a , b ) ;
252256
253257 if ( sortResult === true ) {
254258 return - 1 ;
@@ -283,5 +287,5 @@ export default {
283287 all,
284288 any,
285289 splitwith,
286- sort,
290+ sort
287291} ;
0 commit comments