looop 9001.0.42
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE +21 -0
- data/README.md +108 -0
- data/lib/looop.rb +8 -0
- metadata +49 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fe2468446ba9f2e488be338506d08aa7f7348aa4ae7dff39d2522952e69ba99d
|
4
|
+
data.tar.gz: 3b8b7366e66772c57cdb81c0835078f7bfdec9268c11f4448aff529e4f361cab
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '02799c8862315e9f6260308d684a6272f461a28aa40c1ed32b43d7d52362ddcf0a7abfef3cc02c1d1dfdc08502343db86ab2ea658a0e619429dd61a259177871'
|
7
|
+
data.tar.gz: ee76252b4caeb13fc358e3fbab73a734cb2971e8bf1c74c592ae8ea103f4588fdc085c5e5ce49943b507464df7be3635e2ddb05ded7c5f6b0d4620f6af001169
|
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020 Justin Léger
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
# Looop ♻ ![tests badge](https://img.shields.io/badge/Tests-none-brightgreen) ![loop badge](https://img.shields.io/badge/loop-for-brightgreen) [![license badge](https://img.shields.io/badge/License-MIT-blue)](https://github.com/jusleg/looop/blob/master/LICENSE)
|
2
|
+
Gone are the days where you convert your entire project to Java just to get the nice `for` loop. You can now build similar looking loops that run much slower than your average loop.
|
3
|
+
|
4
|
+
## Get started
|
5
|
+
|
6
|
+
`gem install looop`
|
7
|
+
|
8
|
+
`require 'looop'`
|
9
|
+
|
10
|
+
## How to use Looop
|
11
|
+
|
12
|
+
Looop was built with simplicity as its core value. For this reason, we only offer one method: `Loop.for` (`for` was already taken 😢).
|
13
|
+
|
14
|
+
Let's say you are [DJ Khaled](https://en.wikipedia.org/wiki/DJ_Khaled), a typical Java developer, and you wish to craft a tweet with your signature catchphrase "Another one." repeated **5** times
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
# tweet.rb
|
18
|
+
require 'looop'
|
19
|
+
|
20
|
+
CATCHPHRASE = 'ANOTHER ONE.'
|
21
|
+
tweet = ''
|
22
|
+
Looop.for(index = 1, ->{index <= 5}, ->{index += 1}) do
|
23
|
+
tweet.concat(CATCHPHRASE)
|
24
|
+
end
|
25
|
+
|
26
|
+
puts tweet
|
27
|
+
|
28
|
+
#=> ANOTHER ONE.ANOTHER ONE.ANOTHER ONE.ANOTHER ONE.ANOTHER ONE.
|
29
|
+
```
|
30
|
+
|
31
|
+
## I'm intrigued, what are these ->{} things?
|
32
|
+
|
33
|
+
I'm glad you asked, those are [Procs](https://ruby-doc.org/core-2.6/Proc.html) We'll call these procs while running the loop. This is one of the main reason that make looop a tad bit slower.
|
34
|
+
|
35
|
+
## Do U even Big-O ?!1
|
36
|
+
|
37
|
+
I guess, you can run nested loops if that's what you are asking.
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
height = 5
|
41
|
+
Looop.for(i = 1, ->{ i <= height }, -> {i += 1}) do
|
42
|
+
Looop.for(h = height - i, -> {h > 0 }, -> {h -= 1}) do
|
43
|
+
print " "
|
44
|
+
end
|
45
|
+
Looop.for(j = 1, -> {j <= i}, -> {j += 1}) do
|
46
|
+
print "* "
|
47
|
+
end
|
48
|
+
print "\n"
|
49
|
+
end
|
50
|
+
```
|
51
|
+
|
52
|
+
will print:
|
53
|
+
|
54
|
+
```console
|
55
|
+
*
|
56
|
+
* *
|
57
|
+
* * *
|
58
|
+
* * * *
|
59
|
+
* * * * *
|
60
|
+
```
|
61
|
+
|
62
|
+
## Is this leetcode ready? Can I pass a technical interview with this?
|
63
|
+
|
64
|
+
> Is this leetcode ready?
|
65
|
+
|
66
|
+
It depends, you might be able to solve the base case, but I'd be surprise if you didn't time out during the evaluation of the secret cases.
|
67
|
+
|
68
|
+
> Can I pass a technical interview with this?
|
69
|
+
|
70
|
+
Meh, as long as they don't ask for it to be optimized for performance.
|
71
|
+
|
72
|
+
**TL;DR:** don't.
|
73
|
+
|
74
|
+
## Is it fast
|
75
|
+
|
76
|
+
no
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
Looop.for(i=0, -> {i<1000}, -> {i+=1}) do
|
80
|
+
Looop.for(j=0, -> {j<1000}, -> {j+=1}) do
|
81
|
+
#noop
|
82
|
+
end
|
83
|
+
end
|
84
|
+
```
|
85
|
+
|
86
|
+
was 6 times slower than
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
i = 0
|
90
|
+
while i<1000 do
|
91
|
+
j = 0
|
92
|
+
while j<1000 do
|
93
|
+
#noop
|
94
|
+
j += 1
|
95
|
+
end
|
96
|
+
i += 1
|
97
|
+
end
|
98
|
+
```
|
99
|
+
|
100
|
+
## I don't want to setup a small script to test it but I'm really interested to try it, can you make a repl.it?
|
101
|
+
|
102
|
+
Sure. [here](https://repl.it/@jusleg/looop).
|
103
|
+
|
104
|
+
## Copyright and License
|
105
|
+
Copyright (c) 2020, Justin Leger
|
106
|
+
|
107
|
+
This project is licensed under the [MIT License](https://github.com/jusleg/looop/blob/master/LICENSE).
|
108
|
+
|
data/lib/looop.rb
ADDED
metadata
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: looop
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 9001.0.42
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Justin Leger
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-04-20 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: 'Build for loops with a signature similar to Java for loops. #ThrowbackThursday
|
14
|
+
to when you learned OOP using Java'
|
15
|
+
email: hey@justinleger.ca
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- CHANGELOG.md
|
21
|
+
- LICENSE
|
22
|
+
- README.md
|
23
|
+
- lib/looop.rb
|
24
|
+
homepage: https://github.com/jusleg/looop
|
25
|
+
licenses:
|
26
|
+
- MIT
|
27
|
+
metadata:
|
28
|
+
source_code_uri: https://github.com/jusleg/looop
|
29
|
+
changelog_uri: https://github.com/jusleg/looop/blob/master/CHANGELOG.md
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
requirements: []
|
45
|
+
rubygems_version: 3.0.3
|
46
|
+
signing_key:
|
47
|
+
specification_version: 4
|
48
|
+
summary: A slower way to generate for loops in Ruby with a funky java-like syntax
|
49
|
+
test_files: []
|