time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

README.md (3012B)


      1 <!--
      2 
      3 @license Apache-2.0
      4 
      5 Copyright (c) 2018 The Stdlib Authors.
      6 
      7 Licensed under the Apache License, Version 2.0 (the "License");
      8 you may not use this file except in compliance with the License.
      9 You may obtain a copy of the License at
     10 
     11    http://www.apache.org/licenses/LICENSE-2.0
     12 
     13 Unless required by applicable law or agreed to in writing, software
     14 distributed under the License is distributed on an "AS IS" BASIS,
     15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16 See the License for the specific language governing permissions and
     17 limitations under the License.
     18 
     19 -->
     20 
     21 # doUntil
     22 
     23 > Invoke a function until a test condition is true.
     24 
     25 <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
     26 
     27 <section class="intro">
     28 
     29 </section>
     30 
     31 <!-- /.intro -->
     32 
     33 <!-- Package usage documentation. -->
     34 
     35 <section class="usage">
     36 
     37 ## Usage
     38 
     39 ```javascript
     40 var doUntil = require( '@stdlib/utils/do-until' );
     41 ```
     42 
     43 #### doUntil( fcn, predicate\[, thisArg ] )
     44 
     45 Invokes a `function` until a `predicate` function returns `true`. Note that the `predicate` function is evaluated **after** executing `fcn`; thus, `fcn` **always** executes at least once.
     46 
     47 ```javascript
     48 function predicate( i ) {
     49     return ( i >= 5 );
     50 }
     51 
     52 function beep( i ) {
     53     console.log( 'boop: %d', i );
     54 }
     55 
     56 doUntil( beep, predicate );
     57 /* =>
     58     boop: 0
     59     boop: 1
     60     boop: 2
     61     boop: 3
     62     boop: 4
     63 */
     64 ```
     65 
     66 Both the `predicate` function and the `function` to invoke are provided a single argument:
     67 
     68 -   `i`: iteration number (starting from zero)
     69 
     70 To set the function execution context for the invoked function, provide a `thisArg`.
     71 
     72 ```javascript
     73 function predicate( i ) {
     74     return ( i >= 5 );
     75 }
     76 
     77 function count() {
     78     this.count += 1;
     79 }
     80 
     81 var context = {
     82     'count': 0
     83 };
     84 
     85 doUntil( count, predicate, context );
     86 
     87 console.log( context.count );
     88 // => 5
     89 ```
     90 
     91 </section>
     92 
     93 <!-- /.usage -->
     94 
     95 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
     96 
     97 <section class="notes">
     98 
     99 </section>
    100 
    101 <!-- /.notes -->
    102 
    103 <!-- Package usage examples. -->
    104 
    105 <section class="examples">
    106 
    107 ## Examples
    108 
    109 <!-- eslint no-undef: "error" -->
    110 
    111 ```javascript
    112 var randu = require( '@stdlib/random/base/randu' );
    113 var doUntil = require( '@stdlib/utils/do-until' );
    114 
    115 function predicate() {
    116     return ( randu() <= 0.05 );
    117 }
    118 
    119 function log( i ) {
    120     console.log( i );
    121 }
    122 
    123 doUntil( log, predicate );
    124 ```
    125 
    126 </section>
    127 
    128 <!-- /.examples -->
    129 
    130 <!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    131 
    132 <section class="references">
    133 
    134 </section>
    135 
    136 <!-- /.references -->
    137 
    138 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    139 
    140 <section class="links">
    141 
    142 </section>
    143 
    144 <!-- /.links -->