summaryrefslogtreecommitdiff
path: root/go/series/series.go
diff options
context:
space:
mode:
Diffstat (limited to 'go/series/series.go')
-rw-r--r--go/series/series.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/go/series/series.go b/go/series/series.go
new file mode 100644
index 0000000..55f7eb2
--- /dev/null
+++ b/go/series/series.go
@@ -0,0 +1,25 @@
+package slice
+
+// All returns a list of all substrings of s with length n.
+func All(n int, s string) []string {
+ var ret []string
+ for i, j := 0, n; j <= len(s); i, j = i+1, j+1 {
+ ret = append(ret, s[i:j])
+ }
+ return ret
+}
+
+// UnsafeFirst returns the first substring of s with length n.
+func UnsafeFirst(n int, s string) string {
+ if len(s) >= n {
+ return s[:n]
+ }
+ return ""
+}
+
+func First(n int, s string) (string, bool) {
+ if len(s) >= n {
+ return s[:n], true
+ }
+ return "", false
+}