Git Product home page Git Product logo

loopy's Introduction

Loopy

A functional implementation of loops.

While

// Classic Implementation
const arr1 = [1, -1, 1, -1]
let i = 0
while (i < 4) {
    arr1[i] = arr1[i] + i
}
// Functional Implementation
const { While } = require('@berakocc/loopy')

const arr2 = [1, -1, 1, -1]
While((i) => i < 4, (i) => {
    arr[i] = arr[i] + i
    return i++
}, [i])

DoWhile

// Classic Implementation
let shouldContinue1 = true
let number1 = 1
do {
    number1 += number1
    shouldContinue1 = number1 === 8 ? false : true
} while (shouldContinue1)
// Functional Implementation
const { DoWhile } = require('@berakocc/loopy')

const shouldContinue2 = true
let number2 = 1
DoWhile((b) => b, (b) => {
    number2 += number2
    return number2 === 8 ? !b : b
}, [shouldContinue2])

For

// Classic Implementation
const arr1 = [7, 7, 7]
for (let i = 0; i < 3; ++i) {
    arr[i] = Math.floor(Math.pow(arr[i], i))
}
// Functional Implementation
const { For, defaultMorphics } = require('@berakocc/loopy')

const arr2 = [7, 7, 7]
For({
        initial: 0,
        predicate: (i) => i < 3,
        morphic: defaultMorphics.increment(1),
    },
    (i) => {
        arr[i] = Math.floor(Math.pow(arr[i], i))
    },
    []
)

loopy's People

Contributors

berakoc avatar

Stargazers

 avatar

Watchers

 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.