• Stars
    star
    130
  • Rank 277,575 (Top 6 %)
  • Language
    Solidity
  • Created over 2 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Loopinator

Array looping functions for Solidity.

Current Implementation

uint256[].map

The map function takes a uint256[] memory and a function that takes a uint256 and returns a uint256.

This will loop over the array, applying the function to each element, and returning the new array.

Usage:

// import
import { map } from "./Loopinator.sol";

// apply to use `array.map` syntax
using { map } for uint256[]

// define function for each iteration
function double(uint256 a) pure returns (uint256) {
    return a * 2;
}

contract MyContract {

    function doubleTheNumbers(uint256[] memory numbers) public pure returns (uint256[] memory) {

        return numbers.map(double);

    }

}

uint256[].forEach

The forEach function takes a uint256[] memory and a function that takes a uint256.

This will loop over the array, executing the function on each element.

Usage:

// import
import { forEach } from "./Loopinator.sol";

// apply to use `array.forEach` syntax
using { forEach } for uint256[]

// define function for each iteration
function notZero(uint256 a) pure returns (uint256) {
    require(a != 0, "number is invalid");
}

contract MyContract {

    function allMustBeNonZero(uint256[] memory numbers) public pure {

        numbers.forEach(notZero);

    }

}

uint256[].reduce

The reduce function takes uint256[] memory, a function that takes two uint256 values (the reduced value and the current value, respectively) and returns a uint256 representing the new reduced value, and an initial value.

This will loop over the array, executing the function on the reduced value and each element, and finally returning the reduced value.

Usage:

// import
import { reduce } from "./Loopinator.sol";

// apply to use `array.reduce` syntax
using { reduce } for uint256[]

// define function for each iteration
function sum(uint256 lastValue, uint256 element) internal pure returns (uint256) {
    return lastValue + element;
}

contract MyContract {

    function sumTheNumbers(uint256[] memory numbers) public pure returns (uint256) {

        uint256 initialValue;

        return numbers.reduce(sum, initialValue);

    }

}

More Repositories

1

the-ethereum-virtual-machine

CSS
216
star
2

counter-exploit-toolkit

Solidity
108
star
3

token-types

Efficient Type Driven Smart Contract Interactions
Solidity
104
star
4

ether-deck

Solidity
97
star
5

minimum-viable-proxy

Solidity
88
star
6

uni-v4-core-flashloans

Simple Uniswap V4 Flashloan Receiver
Solidity
81
star
7

huff-style-guide

A mostly mostly reasonable approach to Huff styling.
78
star
8

the-rippler

Solidity
76
star
9

smart-types

Solidity
69
star
10

ether-deck-mk2

Solidity
63
star
11

mutexer

Solidity
58
star
12

ERC-6909

Solidity
56
star
13

ez-bitmap

Solidity
51
star
14

huff-hooks

Uniswap V4 Huff Hooks
Solidity
40
star
15

cursed-struct-token

Solidity
37
star
16

offensive_vyper

Vyper Based Capture The Flag Challenges
Python
35
star
17

monomorphized

Solidity
34
star
18

super-liquidator

Solidity
33
star
19

zk-calculator

Rust
30
star
20

iter-sol

Solidity
29
star
21

inline-yul-style-guide

A mostly mostly reasonable approach to inline Yul styling.
29
star
22

ez-sol

Solidity
28
star
23

safe-counter

Solidity
26
star
24

vy-deepdive

Vyper Deep Dive Notes and Scripts
Assembly
26
star
25

celebrate-push0

Solidity
24
star
26

sol-fun

Solidity
22
star
27

libhuff

optimized huff snippets
Rust
20
star
28

bigbrainchad-eth

JavaScript
20
star
29

unbug

Solidity calldata, memory, transient storage, and storage debugger
Solidity
20
star
30

reverse-subway

Assembly
19
star
31

cursed-functions

Solidity
18
star
32

erc6909-examples

Solidity
13
star
33

poc-template

Solidity
12
star
34

vyper-storage

Solidity
11
star
35

xstream

Solidity
11
star
36

hh-qualifier

Solidity
10
star
37

tcontext

Solidity
10
star
38

type-driven-tokens

Solidity
10
star
39

snarki-boi

Experimental Noir repo. Very important not to get carried away
Solidity
9
star
40

evm-dag-ir

graph-based evm intermediate representation
Rust
9
star
41

prep

Solidity
9
star
42

evm-obj-fmt

Rust
9
star
43

arbies

Python
9
star
44

decktools-mk2

Solidity
9
star
45

vy-6909

Solidity
6
star
46

libecdsa

Solidity
6
star
47

maths

Jupyter Notebook
6
star
48

naturals-lean

Lean Theorem Proving Exercises and Learning Repository
Lean
6
star
49

intent-core

Solidity
6
star
50

jtriley-eth.github.io

HTML
3
star
51

searchooor

Rust
3
star
52

dasy-6909

Solidity
3
star
53

decktools

Rust
3
star
54

quantum-lean

Quantum computing primitives in Lean 4
Lean
3
star
55

sacgeo-solver

Rust
3
star
56

jiterator

tinkering repository for iterator behavior
Rust
2
star
57

sway-research

fa&fo repo for sway
Rust
2
star
58

xsf

Solidity
1
star
59

scuffed-dao

Solidity
1
star
60

flow-state

UI/UX project around Superfluid protocol
JavaScript
1
star
61

temp-spec

temp lang spec with specific in-evm uses, very important not to get carried away
1
star
62

Consensus-Time

Time Consensus Protocol
Solidity
1
star
63

test-proj

Rust
1
star
64

token-accounting

Accounting for ERC20 tokens and Superfluid Super Tokens
TypeScript
1
star
65

ruint-simd

Rust
1
star
66

bitmap-v-memory

gas testing uniswap calls struct against bitmaps
Solidity
1
star
67

portfolio

Svelte
1
star