Giter Club home page Giter Club logo

range's Introduction

range

Functionality of Python's range() in V.

Why

  • a..b in V can only be in increasing order and not in negative order.
  • Lacks inbuilt step which most people need or want.
  • No support for float.

Features

  • Make range arrays easily
  • Make ranges for int and f32
  • Positive as well as Negative Support!
  • No need to write the whole for loop! (this maybe slower than the normal one)
  • Use range for functional programming
  • Full Python's range() functionality

Installation

  • Via git clone
    • git clone https://github.com/Delta456/range
  • Via v install
    • v install range
  • Via vpkg
    • vpkg install range

Usage

  • range.int(start:0, stop:value, step:1) makes a range of int with the following parameters:

    • start: start value of the range by default it's 0
    • stop: stop value of the range
    • step: step value of the range by default it's 1
  • range.float(start:0.0, stop:value, step:1.0) makes a range of f32 with the following parameters:

    • start: start value of the range by default it's 0.0
    • stop: stop value of the range
    • step: step value of the range by default it's 1.0

Note: If range.int(step:0) or range.float(step:0) then an error will be raised because step cannot be zero.

In main.v

import delta456.range

fn main() {
    // using range.int
    for i in range.int(stop:10) {
        println(i)
    }

    for i in range.int(start:1, stop:10) {
        println(i)
    }

    for i in range.int(start:1, stop:10, step:2) {
        println(i)
    }

    for i in range.int(start:10, stop:1, step:-1) {
        println(i)
    }

    for i in range.int(start:-5, stop:-1, step: 1) {
        println(i)
    }

    // using range.float
    for i in in range.float(stop:10) {
        println(i)
    }

    for i in in range.float(stop:10, step:0.2) {
        println(i)
    }

    for i in in range.float(start:0.1, stop:10) {
        println(i)
    }

    for i in in range.float(start:10, stop:1.0, step:-0.2) {
        println(i)
    }

    for i in in range.float(start:-10, stop:-1.0, step:0.2) {
        println(i)
    }
}

Acknowledgments

I thank @Hungry Blue Dev for giving me the idea of using a struct with default parameters so that range function for each type can be the same.

License

Released under MIT

range's People

Contributors

delta456 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.