kstreams

package
v1.0.4-Realize Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

* 包kstreams包含了对数据处理的相关封装及描述

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EachLine

func EachLine(eachString string, eachFunc func(index int, line string))

对传入的eachString进行按行切片后再进行遍历

该函数会预先对“\r\n”进行处理替换为“\n”。

在遍历到每一行的时候会将结果index和line作为入参传入eachFunc中进行调用。

index表示了当前行的行号(由0开始),line表示了当前行的内容。

func EachLineOff

func EachLineOff(eachString string, eachFunc func(index int, line string) error) error

对传入的eachString进行按行切片后再进行可中断的遍历

该函数会预先对“\r\n”进行处理替换为“\n”。

在遍历到每一行的时候会将结果index和line作为入参传入eachFunc中进行调用。

index表示了当前行的行号(由0开始),line表示了当前行的内容。

当eachFunc的返回值不为nil时,则中断遍历,并返回error。

func EachMapSort

func EachMapSort(eachMap interface{}, eachFunc interface{})

对传入的eachMap进行排序后再进行遍历

确保eachFunc传入的类型为func,并且其拥有两个入参,分别对应eachMap的Key类型和Value类型。

在EachMapSort对eachMap排序之后会进行一次遍历,并且将Key和Value分别传入eachFunc这个函数里进行调用。

使用示例如下:

mInt := map[int]string {
	3: "line 3",
	1: "line 1",
	2: "line 2",
}
EachMapSort(mInt, func(key int, value string) {
	t.Log(key, value)
})
t.Log("------------------------------------")
mString := map[string]string {
	"3": "line 3",
	"1": "line 1",
	"b": "line b",
	"2": "line 2",
	"a": "line a",
}
EachMapSort(mString, func(key string, value string) {
	t.Log(key, value)
})

Types

This section is empty.

Jump to

Keyboard shortcuts

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