list

package
v0.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Concat added in v0.0.9

func Concat[A any, LA ~[]A, LLA ~[]LA](xss LLA) []A

func Conform added in v0.0.4

func Conform[A any, CA Class[A]](c CA) func(t *testing.T, x, y, z List[A])

Conform returns a function testing if the implementation abides by its laws.

func FoldR added in v0.0.9

func FoldR[A, B any, LA ~[]A](f func(A, B) B, z B, xs LA) B

func Intercalate added in v0.0.9

func Intercalate[A any, LA ~[]A, LLA ~[]LA](xs LA, xss LLA) []A
Example (Arraybyte)
package main

import (
	"fmt"

	"github.com/calebcase/base/data/list"
)

func main() {
	fmt.Println(string(list.Intercalate(
		[]byte(", "),
		[][]byte{
			[]byte("Lorem"),
			[]byte("ipsum"),
			[]byte("dolor"),
		},
	)))

}
Output:

Lorem, ipsum, dolor
Example (Listbyte)
package main

import (
	"fmt"

	"github.com/calebcase/base/data/list"
)

func main() {
	fmt.Println(string(list.Intercalate(
		list.List[byte](", "),
		list.List[list.List[byte]]{
			list.List[byte]("Lorem"),
			list.List[byte]("ipsum"),
			list.List[byte]("dolor"),
		},
	)))

}
Output:

Lorem, ipsum, dolor

func Intersperse added in v0.0.9

func Intersperse[A any, LA ~[]A](v A, xs LA) []A
Example
package main

import (
	"fmt"

	"github.com/calebcase/base/data/list"
)

func main() {
	fmt.Println(string(list.Intersperse(',', list.List[byte]("abcde"))))

}
Output:

a,b,c,d,e

func Map added in v0.0.9

func Map[A, B any, LA ~[]A](fn func(A) B, xs LA) []B
Example
package main

import (
	"fmt"

	"github.com/calebcase/base/data/list"
)

func main() {
	fmt.Println(
		list.Map(
			func(x int) int {
				return x + 1
			},
			list.List[int]{1, 2, 3},
		),
	)

}
Output:

[2 3 4]

func NewEqualFn added in v0.0.5

func NewEqualFn[A any, LA ~[]A](e eq.Class[A]) func(x, y LA) bool

NewEqualFn returns a list equality checking function given the eq.Class for the type A.

func NonEmptySubsequences added in v0.0.9

func NonEmptySubsequences[A any, LA ~[]A](la LA) [][]A
Example
package main

import (
	"fmt"

	"github.com/calebcase/base/data/list"
)

func main() {
	fmt.Println(list.NonEmptySubsequences([]int{1, 2, 3}))

}
Output:

[[1] [2] [1 2] [3] [1 3] [2 3] [1 2 3]]

func Reverse added in v0.0.9

func Reverse[A any, LA ~[]A](xs LA) []A
Example
package main

import (
	"fmt"

	"github.com/calebcase/base/data/list"
)

func main() {
	fmt.Println(list.Reverse(list.List[int]{}))
	fmt.Println(list.Reverse(list.List[int]{42}))
	fmt.Println(list.Reverse(list.List[int]{2, 5, 7}))

}
Output:

[]
[42]
[7 5 2]

func Subsequences added in v0.0.9

func Subsequences[A any, LA ~[]A](xs LA) [][]A
Example
package main

import (
	"fmt"

	"github.com/calebcase/base/data/list"
)

func main() {
	fmt.Println(list.Subsequences([]int{1, 2, 3}))

}
Output:

[[] [1] [2] [1 2] [3] [1 3] [2 3] [1 2 3]]

func Transpose added in v0.0.9

func Transpose[A any, LA ~[]A, LLA ~[]LA](xss LLA) [][]A
Example (Equal)
package main

import (
	"fmt"

	"github.com/calebcase/base/data/list"
)

func main() {
	fmt.Println(list.Transpose([][]int{{1, 2, 3}, {4, 5, 6}}))

}
Output:

[[1 4] [2 5] [3 6]]
Example (Mixed)
package main

import (
	"fmt"

	"github.com/calebcase/base/data/list"
)

func main() {
	fmt.Println(list.Transpose([][]int{{10, 11}, {20}, {}, {30, 31, 32}}))

}
Output:

[[10 20 30] [11 31] [32]]

Types

type Class

type Class[A any] interface {
	monoid.Class[List[A]]
}

type List added in v0.0.4

type List[A any] []A

func (List[A]) DEmpty added in v0.0.6

func (l List[A]) DEmpty() bool

func (List[A]) DRest added in v0.0.4

func (l List[A]) DRest() data.Data[A]

func (List[A]) DValue added in v0.0.4

func (l List[A]) DValue() A

type T added in v0.0.9

type T[A any] interface{}

type Type

type Type[
	A any,
] struct {
	monoid.Type[List[A]]
}

func NewType

func NewType[
	A any,
]() Type[A]

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL