mirror of
https://github.com/rjNemo/underscore
synced 2026-06-11 04:56:44 +00:00
Doc site (#5)
* docs: install compose theme * docs: create collections page * docs: create collections page * docs: change logo Co-authored-by: Ruidy <rnemausat@newstore.com>
This commit is contained in:
parent
6f8c303297
commit
97e0a6e7e7
13 changed files with 300 additions and 1 deletions
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
[submodule "docs/themes/compose"]
|
||||||
|
path = docs/themes/compose
|
||||||
|
url = https://github.com/onweru/compose/
|
||||||
5
Makefile
5
Makefile
|
|
@ -1,2 +1,5 @@
|
||||||
test:
|
test:
|
||||||
docker build .
|
docker build .
|
||||||
|
|
||||||
|
doc:
|
||||||
|
cd docs && hugo server -D
|
||||||
0
docs/.hugo_build.lock
Normal file
0
docs/.hugo_build.lock
Normal file
6
docs/archetypes/default.md
Normal file
6
docs/archetypes/default.md
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
---
|
||||||
|
title: "{{ replace .Name "-" " " | title }}"
|
||||||
|
date: {{ .Date }}
|
||||||
|
draft: true
|
||||||
|
---
|
||||||
|
|
||||||
46
docs/assets/sass/_variables.sass
Normal file
46
docs/assets/sass/_variables.sass
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
html
|
||||||
|
--color-mode: "light"
|
||||||
|
--light: #fff
|
||||||
|
--dark: rgb(28,28,30)
|
||||||
|
--haze: #f2f5f7
|
||||||
|
--bubble: rgb(36,36,38)
|
||||||
|
--accent: var(--haze)
|
||||||
|
--bg: var(--light)
|
||||||
|
--code-bg: var(--accent)
|
||||||
|
--overlay: var(--light)
|
||||||
|
--text: #111
|
||||||
|
--font: 'Metropolis', sans-serif
|
||||||
|
--border-color: #eee
|
||||||
|
--inline-color: darkgoldenrod
|
||||||
|
--theme: #209CEE
|
||||||
|
--ease: ease
|
||||||
|
|
||||||
|
@mixin darkmode
|
||||||
|
--color-mode: "dark"
|
||||||
|
--theme: #209CEE
|
||||||
|
--bg: var(--dark)
|
||||||
|
--text: #eee
|
||||||
|
--accent: var(--bubble)
|
||||||
|
--overlay: var(--bubble)
|
||||||
|
--border-color: transparent
|
||||||
|
*
|
||||||
|
box-shadow: none !important
|
||||||
|
|
||||||
|
&[data-mode="dark"]
|
||||||
|
@include darkmode
|
||||||
|
.color
|
||||||
|
&_choice
|
||||||
|
&::after
|
||||||
|
background-image: url(../icons/moon.svg)
|
||||||
|
|
||||||
|
&.dark:not([data-mode="light"])
|
||||||
|
@media (prefers-color-scheme: dark)
|
||||||
|
@include darkmode
|
||||||
|
|
||||||
|
%narrow
|
||||||
|
max-width: 750px
|
||||||
|
margin: 0 auto
|
||||||
|
|
||||||
|
blockquote
|
||||||
|
+ .highlight_wrap
|
||||||
|
margin-top: 2.25rem
|
||||||
12
docs/config.toml
Normal file
12
docs/config.toml
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
baseURL = 'http://example.org/'
|
||||||
|
languageCode = 'en-us'
|
||||||
|
title = 'Underscore'
|
||||||
|
theme = "compose" # edit this if you'ld rather use a fork of this repo
|
||||||
|
enableRobotsTXT = true
|
||||||
|
[outputs]
|
||||||
|
home = ["HTML", "RSS","JSON"]
|
||||||
|
[params]
|
||||||
|
logo.lightMode = "logo.png"
|
||||||
|
logo.darkMode = "logo.png"
|
||||||
|
author.name = "Ruidy"
|
||||||
|
author.url = "https://github.com/rjNemo"
|
||||||
12
docs/content/docs/_index.md
Normal file
12
docs/content/docs/_index.md
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
+++ title = "Underscore"
|
||||||
|
[data]
|
||||||
|
baseChartOn = 3
|
||||||
|
colors = ["#627c62", "#11819b", "#ef7f1a", "#4e1154"]
|
||||||
|
columnTitles = ["Section", "Status", "Author"]
|
||||||
|
+++
|
||||||
|
|
||||||
|
{{< column >}}
|
||||||
|
|
||||||
|
`underscore` is a `Go` library providing useful functional programming helpers without extending any built-in objects.
|
||||||
|
|
||||||
|
It is mostly a port from the `underscore.js` library based on generics brought by `go1.18`.
|
||||||
212
docs/content/docs/collections.md
Normal file
212
docs/content/docs/collections.md
Normal file
|
|
@ -0,0 +1,212 @@
|
||||||
|
---
|
||||||
|
title: "Collections"
|
||||||
|
date: 2021-12-30T13:24:39-04:00
|
||||||
|
---
|
||||||
|
|
||||||
|
## Each
|
||||||
|
|
||||||
|
`Each` iterates over a slice of elements, yielding each in turn to an action function.
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
u "github.com/rjNemo/underscore"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
names := []string{"Alice", "Bob", "Charles"}
|
||||||
|
res := make([]string, 0)
|
||||||
|
|
||||||
|
u.Each(names, func(n string) {
|
||||||
|
res = append(res, fmt.Sprintf("Hi %s", n))
|
||||||
|
})
|
||||||
|
fmt.Println(res) // {"Hi Alice", "Hi Bob", "Hi Charles"}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Every
|
||||||
|
|
||||||
|
`Every` returns true if all the values in the slice pass the predicate truth test.\
|
||||||
|
Short-circuits and stops traversing the slice if a false element is found.
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
u "github.com/rjNemo/underscore"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
nums := []int{1, 3, 5, 7, 9}
|
||||||
|
isOdd := func(n int) bool { return n%2 != 0 }
|
||||||
|
fmt.Println(u.Every(nums, isOdd)) // true
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Filter
|
||||||
|
|
||||||
|
`Filter` looks through each value in the slice, returning a slice of all the values that pass a truth test (predicate).
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
u "github.com/rjNemo/underscore"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
nums := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
|
||||||
|
isEven := func(n int) bool { return n%2 == 0 }
|
||||||
|
fmt.Println(u.Filter(nums, isEven)) // {0, 2, 4, 6, 8}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Find
|
||||||
|
|
||||||
|
Find looks through each value in the slice, returning the first one that passes a truth test (predicate), or the default
|
||||||
|
value for the type and an error if no value passes the test. The function returns as soon as it finds an acceptable
|
||||||
|
element, and doesn't traverse the entire slice.
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
u "github.com/rjNemo/underscore"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
nums := []int{2, 4, 5, 6, 8, 0}
|
||||||
|
isOdd := func(n int) bool { return n%2 != 0 }
|
||||||
|
|
||||||
|
n, err := u.Find(nums, isOdd)
|
||||||
|
fmt.Println(n) // 5
|
||||||
|
fmt.Println(err) // nil
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Map
|
||||||
|
|
||||||
|
`Map` produces a new slice of values by mapping each value in the slice through a transform function.
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
u "github.com/rjNemo/underscore"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
nums := []int{1, 2, 3}
|
||||||
|
toSquare := func(n int) int {
|
||||||
|
return n * n
|
||||||
|
}
|
||||||
|
fmt.Println(u.Map(nums, toSquare)) // {1, 4, 9}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Max
|
||||||
|
|
||||||
|
`Max` returns the maximum value in the slice. This function can currently only compare numbers reliably. This function
|
||||||
|
uses operator `<`.
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
u "github.com/rjNemo/underscore"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
nums := []int{1, 9, 2, 8, 3, 7, 4, 6, 5}
|
||||||
|
fmt.Println(u.Max(nums)) // 9
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Min
|
||||||
|
|
||||||
|
`Min` returns the minimum value in the slice. This function can currently only compare numbers reliably. This function
|
||||||
|
uses operator `<`.
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
u "github.com/rjNemo/underscore"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
nums := []int{1, 9, 2, 8, 3, 7, 4, 6, 5}
|
||||||
|
fmt.Println(u.Min(nums)) // 1
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Partition
|
||||||
|
|
||||||
|
`Partition` splits the slice into two slices: one whose elements all satisfy predicate and one whose elements all do not
|
||||||
|
satisfy predicate.
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
u "github.com/rjNemo/underscore"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
nums := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
|
||||||
|
isEven := func(n int) bool { return n%2 == 0 }
|
||||||
|
|
||||||
|
evens, odds := u.Partition(nums, isEven)
|
||||||
|
fmt.Println(evens) // {0, 2, 4, 6, 8}
|
||||||
|
fmt.Println(odds) // {1, 3, 5, 7, 9}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Reduce
|
||||||
|
|
||||||
|
`Reduce` combine a list of values into a single value. `acc` is the initial state, and each successive step of it should
|
||||||
|
be returned by the reduction function.
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
u "github.com/rjNemo/underscore"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
nums := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
|
||||||
|
sum := func(n, acc int) int { return n + acc }
|
||||||
|
fmt.Println(u.Reduce(nums, sum, 0)) // 45
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Some
|
||||||
|
|
||||||
|
`Some` returns true if any of the values in the slice pass the predicate truth test. Short-circuits and stops traversing
|
||||||
|
the slice if a true element is found.
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
u "github.com/rjNemo/underscore"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
nums := []int{1, 2, 4, 6, 8}
|
||||||
|
isEven := func(n int) bool { return n%2 == 0 }
|
||||||
|
fmt.Println(u.Some(nums, isEven)) // true
|
||||||
|
}
|
||||||
|
```
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1 @@
|
||||||
|
{"Target":"css/styles.35cccf4dc83860130d466a273c4bd3f1342dc22b167106c704a21ae7307d2d98f4701138b92f3fe17054f928a248863a30ad7863fe6b3816582123ff58f21da6.css","MediaType":"text/css","Data":{"Integrity":"sha512-NczPTcg4YBMNRmonPEvT8TQtwisWcQbHBKIa5zB9LZj0cBE4uS8/4XBU+SiiSIY6MK14Y/5rOBZYISP/WPIdpg=="}}
|
||||||
BIN
docs/static/logo.png
vendored
Normal file
BIN
docs/static/logo.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.4 KiB |
1
docs/themes/compose
vendored
Submodule
1
docs/themes/compose
vendored
Submodule
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 362af2409158972008f1dff8ee5e887d6ce88257
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 10 KiB |
Loading…
Reference in a new issue