time-to-botec

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

README.md (2232B)


      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 # isIteratorLike
     22 
     23 > Test if a value is [`iterator`][mdn-iterator-protocol]-like.
     24 
     25 <section class="usage">
     26 
     27 ## Usage
     28 
     29 ```javascript
     30 var isIteratorLike = require( '@stdlib/assert/is-iterator-like' );
     31 ```
     32 
     33 #### isIteratorLike( value )
     34 
     35 Tests if a `value` is [`iterator`][mdn-iterator-protocol]-like.
     36 
     37 <!-- eslint-disable no-restricted-syntax, no-empty-function -->
     38 
     39 ```javascript
     40 var obj = {
     41     'next': function noop() {}
     42 };
     43 var bool = isIteratorLike( obj );
     44 // returns true
     45 
     46 bool = isIteratorLike( {} );
     47 // returns false
     48 ```
     49 
     50 </section>
     51 
     52 <!-- /.usage -->
     53 
     54 <section class="notes">
     55 
     56 ## Notes
     57 
     58 -   An [iterator protocol-compliant object][mdn-iterator-protocol] is an `object` having a `next` method following the [iterator protocol][mdn-iterator-protocol].
     59 -   As full [iterator][mdn-iterator-protocol] compliance is **impossible** to achieve without evaluating an [iterator][mdn-iterator-protocol], this function checks **only** for interface compliance.
     60 
     61 </section>
     62 
     63 <!-- /.notes -->
     64 
     65 <section class="examples">
     66 
     67 ## Examples
     68 
     69 <!-- eslint no-undef: "error" -->
     70 
     71 ```javascript
     72 var noop = require( '@stdlib/utils/noop' );
     73 var isIteratorLike = require( '@stdlib/assert/is-iterator-like' );
     74 
     75 var obj = {
     76     'next': noop
     77 };
     78 var bool = isIteratorLike( obj );
     79 // returns true
     80 
     81 bool = isIteratorLike( {} );
     82 // returns false
     83 
     84 bool = isIteratorLike( [] );
     85 // returns false
     86 
     87 bool = isIteratorLike( null );
     88 // returns false
     89 ```
     90 
     91 </section>
     92 
     93 <!-- /.examples -->
     94 
     95 <section class="links">
     96 
     97 [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol
     98 
     99 </section>
    100 
    101 <!-- /.links -->