-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
134 changed files
with
7,938 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: 🧪 Test/Lint | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
test-lint: | ||
name: Test/Lint | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
go-version: [ '1.21', '1.22' ] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Setup Go ${{ matrix.go-version }} | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
|
||
- name: Tests | ||
run: go test ./... | ||
|
||
- name: Linter | ||
uses: golangci/golangci-lint-action@v4 | ||
with: | ||
version: v1.56.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,5 @@ | |
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
run: | ||
skip-files: | ||
- ".*_test.go" | ||
|
||
linters: | ||
enable: | ||
- asasalint | ||
- asciicheck | ||
- bidichk | ||
- bodyclose | ||
#! - containedctx | ||
- contextcheck | ||
#! - copyloopvar | ||
- cyclop | ||
- decorder | ||
#! - depguard | ||
- dogsled | ||
- dupl | ||
- dupword | ||
- durationcheck | ||
- errcheck | ||
- errchkjson | ||
- errname | ||
- errorlint | ||
- execinquery | ||
- exhaustive | ||
#! - exhaustruct | ||
- exportloopref | ||
#! - forbidigo | ||
- forcetypeassert | ||
- funlen | ||
- gci | ||
- ginkgolinter | ||
- gocheckcompilerdirectives | ||
- gochecknoglobals | ||
- gochecknoinits | ||
- gochecksumtype | ||
- gocognit | ||
- goconst | ||
- gocritic | ||
- gocyclo | ||
- godot | ||
- godox | ||
- goerr113 | ||
- gofmt | ||
- gofumpt | ||
- goheader | ||
- goimports | ||
- gomnd | ||
- gomoddirectives | ||
- gomodguard | ||
- goprintffuncname | ||
- gosec | ||
- gosimple | ||
- gosmopolitan | ||
- govet | ||
- grouper | ||
- importas | ||
- inamedparam | ||
- ineffassign | ||
- interfacebloat | ||
#! - intrange | ||
#! - ireturn | ||
- lll | ||
- loggercheck | ||
- maintidx | ||
- makezero | ||
- mirror | ||
- misspell | ||
- musttag | ||
- nakedret | ||
- nestif | ||
- nilerr | ||
- nilnil | ||
- nlreturn | ||
- noctx | ||
- nolintlint | ||
- nonamedreturns | ||
- nosprintfhostport | ||
- paralleltest | ||
- perfsprint | ||
- prealloc | ||
- predeclared | ||
- promlinter | ||
- protogetter | ||
- reassign | ||
- revive | ||
- rowserrcheck | ||
- sloglint | ||
- spancheck | ||
- sqlclosecheck | ||
- staticcheck | ||
- stylecheck | ||
- tagalign | ||
- tagliatelle | ||
- tenv | ||
- testableexamples | ||
- testifylint | ||
- testpackage | ||
- thelper | ||
- tparallel | ||
- typecheck | ||
- unconvert | ||
- unparam | ||
- unused | ||
- usestdlibvars | ||
- varnamelen | ||
- wastedassign | ||
- whitespace | ||
- wrapcheck | ||
- wsl | ||
- zerologlint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,76 @@ | ||
# iter | ||
Go Library for Iterators | ||
# Iter | ||
|
||
Iter is a _simple_ and _ergonomic_ package for implementing and utilizing | ||
iterators in Golang. | ||
|
||
## Features | ||
|
||
- Easy to implement Iterable interface | ||
- Standardized toolset for utilizing iterables | ||
|
||
## Limitions | ||
|
||
While this package aims to provide a fluid way of writing code, it also strives | ||
to be as efficient as possible. However, due to the inherent nature and | ||
idiosyncrasies of Go, it will always be more efficient to write code that | ||
utilizes the language's primitives. | ||
|
||
This package does not aim to be the fastest way to run Go. | ||
|
||
## Getting Started | ||
|
||
```Go | ||
package main | ||
|
||
import ( | ||
"github.com/theMagicalKarp/iter/pkg/iter" | ||
"github.com/theMagicalKarp/iter/pkg/itertools" | ||
) | ||
|
||
func main() { | ||
// create iterator from static values | ||
numbers := iter.New(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) | ||
|
||
// filter to collect even numbers | ||
evenNumbers := itertools.Filter(numbers, func(n int) bool { | ||
return n%2 == 0 | ||
}) | ||
|
||
// square numbers and convert to strings | ||
squaredNumbers := itertools.Map(evenNumbers, func(n int) int { | ||
return n*n | ||
}) | ||
|
||
itertools.Print(squaredNumbers) | ||
// 0, 4, 16, 36, 64 | ||
} | ||
``` | ||
|
||
## How | ||
|
||
Everything in the iter packages utilizes a single interface for reading data. | ||
|
||
```Go | ||
// Iterable represents a generic iterable collection. | ||
type Iterable[T any] interface { | ||
// Next returns the next element in the collection and a boolean value indicating if the value was found. | ||
Next() (T, bool) | ||
} | ||
``` | ||
|
||
## Why | ||
|
||
Universal iterable interfaces are foundational to powerful problem solving. When | ||
using iterables as the standard for functional communication, you can create and | ||
utilize standard sets of libraries and structs seamlessly. This results in | ||
clever and easy-to-understand solutions. | ||
|
||
Since many of the itertools functions accept and return iterables, you can plug | ||
and play various functions to achieve a desired result. | ||
|
||
## Test | ||
|
||
```Shell | ||
go test ./... | ||
golangci-lint run | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## What | ||
|
||
Solution to part 2 of https://adventofcode.com/2023/day/1. | ||
|
||
``` | ||
go run main.go | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
"unicode" | ||
|
||
"github.com/theMagicalKarp/iter/pkg/itertools" | ||
"github.com/theMagicalKarp/iter/pkg/predicates" | ||
) | ||
|
||
var WORD_TO_DIGIT = map[string]int{ | ||
"one": 1, | ||
"two": 2, | ||
"three": 3, | ||
"four": 4, | ||
"five": 5, | ||
"six": 6, | ||
"seven": 7, | ||
"eight": 8, | ||
"nine": 9, | ||
} | ||
|
||
func ToDigit(s string) int { | ||
if unicode.IsDigit(rune(s[0])) { | ||
return int(s[0] - '0') | ||
} | ||
|
||
for k, v := range WORD_TO_DIGIT { | ||
if strings.HasPrefix(s, k) { | ||
return v | ||
} | ||
} | ||
|
||
return -1 | ||
} | ||
|
||
func ChopString(s string) func(int) string { | ||
return func(i int) string { | ||
return s[i:] | ||
} | ||
} | ||
|
||
func ProcessLine(line string) int { | ||
irange := itertools.Range(0, len(line)) | ||
subStrings := itertools.Map(irange, ChopString(line)) | ||
allDigits := itertools.Map(subStrings, ToDigit) | ||
positiveDigits := itertools.Filter(allDigits, predicates.Positive) | ||
|
||
first, more := positiveDigits.Next() | ||
if !more { | ||
return 0 | ||
} | ||
|
||
last, found := itertools.Last(positiveDigits) | ||
if !found { | ||
last = first | ||
} | ||
|
||
return first*10 + last | ||
} | ||
|
||
func main() { | ||
f, err := os.Open("examples/example1/input.txt") | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer f.Close() | ||
|
||
lines := itertools.Lines(f) | ||
readings := itertools.Map(lines, ProcessLine) | ||
fmt.Println(itertools.Sum(readings)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## What | ||
|
||
Solution to part 2 of https://adventofcode.com/2023/day/2. | ||
|
||
``` | ||
go run main.go | ||
``` |
Oops, something went wrong.