mirror of
https://github.com/IBM/fp-go.git
synced 2025-08-10 22:31:32 +02:00
Merge pull request #14 from IBM/cleue-add-missing-methods
fix: add missing array traversal to either
This commit is contained in:
@@ -280,3 +280,11 @@ func IsNonNil[A any](as []A) bool {
|
||||
func ConstNil[A any]() []A {
|
||||
return array.ConstNil[[]A]()
|
||||
}
|
||||
|
||||
func SliceRight[A any](start int) func([]A) []A {
|
||||
return G.SliceRight[[]A](start)
|
||||
}
|
||||
|
||||
func Copy[A any](b []A) []A {
|
||||
return G.Copy(b)
|
||||
}
|
||||
|
@@ -180,3 +180,21 @@ func MatchLeft[AS ~[]A, A, B any](onEmpty func() B, onNonEmpty func(A, AS) B) fu
|
||||
return onNonEmpty(as[0], as[1:])
|
||||
}
|
||||
}
|
||||
|
||||
func Slice[AS ~[]A, A any](start int, end int) func(AS) AS {
|
||||
return func(a AS) AS {
|
||||
return a[start:end]
|
||||
}
|
||||
}
|
||||
|
||||
func SliceRight[AS ~[]A, A any](start int) func(AS) AS {
|
||||
return func(a AS) AS {
|
||||
return a[start:]
|
||||
}
|
||||
}
|
||||
|
||||
func Copy[AS ~[]A, A any](b AS) AS {
|
||||
buf := make(AS, len(b))
|
||||
copy(buf, b)
|
||||
return buf
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@ package readerioeither
|
||||
|
||||
// Code generated by go generate; DO NOT EDIT.
|
||||
// This file was generated by robots at
|
||||
// 2023-07-28 15:42:22.8252325 +0200 CEST m=+0.010212601
|
||||
// 2023-07-28 22:48:20.012425 +0200 CEST m=+0.019517901
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
@@ -17,7 +17,7 @@ package generic
|
||||
|
||||
// Code generated by go generate; DO NOT EDIT.
|
||||
// This file was generated by robots at
|
||||
// 2023-07-28 15:42:22.8252325 +0200 CEST m=+0.010212601
|
||||
// 2023-07-28 22:48:20.012425 +0200 CEST m=+0.019517901
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
46
either/array.go
Normal file
46
either/array.go
Normal file
@@ -0,0 +1,46 @@
|
||||
// Copyright (c) 2023 IBM Corp.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package either
|
||||
|
||||
import (
|
||||
F "github.com/IBM/fp-go/function"
|
||||
RA "github.com/IBM/fp-go/internal/array"
|
||||
)
|
||||
|
||||
// TraverseArray transforms an array
|
||||
func TraverseArrayG[GA ~[]A, GB ~[]B, E, A, B any](f func(A) Either[E, B]) func(GA) Either[E, GB] {
|
||||
return RA.Traverse[GA](
|
||||
Of[E, GB],
|
||||
Map[E, GB, func(B) GB],
|
||||
Ap[GB, E, B],
|
||||
|
||||
f,
|
||||
)
|
||||
}
|
||||
|
||||
// TraverseArray transforms an array
|
||||
func TraverseArray[E, A, B any](f func(A) Either[E, B]) func([]A) Either[E, []B] {
|
||||
return TraverseArrayG[[]A, []B](f)
|
||||
}
|
||||
|
||||
func SequenceArrayG[GA ~[]A, GOA ~[]Either[E, A], E, A any](ma GOA) Either[E, GA] {
|
||||
return TraverseArrayG[GOA, GA](F.Identity[Either[E, A]])(ma)
|
||||
}
|
||||
|
||||
// SequenceArray converts a homogeneous sequence of either into an either of sequence
|
||||
func SequenceArray[E, A any](ma []Either[E, A]) Either[E, []A] {
|
||||
return SequenceArrayG[[]A](ma)
|
||||
}
|
@@ -15,7 +15,7 @@
|
||||
|
||||
// Code generated by go generate; DO NOT EDIT.
|
||||
// This file was generated by robots at
|
||||
// 2023-07-28 15:42:24.2984201 +0200 CEST m=+0.008649601
|
||||
// 2023-07-28 22:48:23.165015 +0200 CEST m=+0.038998801
|
||||
package either
|
||||
|
||||
|
||||
|
@@ -15,7 +15,7 @@
|
||||
|
||||
// Code generated by go generate; DO NOT EDIT.
|
||||
// This file was generated by robots at
|
||||
// 2023-07-28 15:42:51.4021911 +0200 CEST m=+0.009058101
|
||||
// 2023-07-28 22:48:40.161663 +0200 CEST m=+0.009458101
|
||||
package function
|
||||
// Combinations for a total of 1 arguments
|
||||
|
||||
|
@@ -15,7 +15,7 @@
|
||||
|
||||
// Code generated by go generate; DO NOT EDIT.
|
||||
// This file was generated by robots at
|
||||
// 2023-07-28 15:42:43.1490717 +0200 CEST m=+0.010222401
|
||||
// 2023-07-28 22:48:27.8029852 +0200 CEST m=+0.051432001
|
||||
package function
|
||||
|
||||
// Pipe0 takes an initial value t0 and successively applies 0 functions where the input of a function is the return value of the previous function
|
||||
|
@@ -15,7 +15,7 @@
|
||||
|
||||
// Code generated by go generate; DO NOT EDIT.
|
||||
// This file was generated by robots at
|
||||
// 2023-07-28 15:42:58.8116745 +0200 CEST m=+0.008252901
|
||||
// 2023-07-28 22:48:46.7920356 +0200 CEST m=+0.045177201
|
||||
package identity
|
||||
|
||||
|
||||
|
@@ -15,7 +15,7 @@
|
||||
|
||||
// Code generated by go generate; DO NOT EDIT.
|
||||
// This file was generated by robots at
|
||||
// 2023-07-28 15:43:00.6284756 +0200 CEST m=+0.013494201
|
||||
// 2023-07-28 22:48:49.4210571 +0200 CEST m=+0.040316501
|
||||
package apply
|
||||
|
||||
|
||||
|
@@ -15,7 +15,7 @@
|
||||
|
||||
// Code generated by go generate; DO NOT EDIT.
|
||||
// This file was generated by robots at
|
||||
// 2023-07-28 15:43:07.1016885 +0200 CEST m=+0.039744901
|
||||
// 2023-07-28 22:48:57.7378739 +0200 CEST m=+0.063371401
|
||||
package io
|
||||
|
||||
|
||||
|
@@ -15,7 +15,7 @@
|
||||
|
||||
// Code generated by go generate; DO NOT EDIT.
|
||||
// This file was generated by robots at
|
||||
// 2023-07-28 15:43:07.1026882 +0200 CEST m=+0.040744601
|
||||
// 2023-07-28 22:48:57.7499229 +0200 CEST m=+0.075420401
|
||||
package generic
|
||||
|
||||
|
||||
|
@@ -15,7 +15,7 @@
|
||||
|
||||
// Code generated by go generate; DO NOT EDIT.
|
||||
// This file was generated by robots at
|
||||
// 2023-07-28 15:43:09.9125541 +0200 CEST m=+0.083065801
|
||||
// 2023-07-28 22:49:00.7618943 +0200 CEST m=+0.065441701
|
||||
package ioeither
|
||||
|
||||
|
||||
|
@@ -15,7 +15,7 @@
|
||||
|
||||
// Code generated by go generate; DO NOT EDIT.
|
||||
// This file was generated by robots at
|
||||
// 2023-07-28 15:43:09.9180997 +0200 CEST m=+0.088611401
|
||||
// 2023-07-28 22:49:00.7765028 +0200 CEST m=+0.080050201
|
||||
package generic
|
||||
|
||||
|
||||
|
@@ -15,7 +15,7 @@
|
||||
|
||||
// Code generated by go generate; DO NOT EDIT.
|
||||
// This file was generated by robots at
|
||||
// 2023-07-28 15:43:14.520059 +0200 CEST m=+0.012057201
|
||||
// 2023-07-28 22:49:03.8471425 +0200 CEST m=+0.087124201
|
||||
package iooption
|
||||
|
||||
|
||||
|
@@ -15,7 +15,7 @@
|
||||
|
||||
// Code generated by go generate; DO NOT EDIT.
|
||||
// This file was generated by robots at
|
||||
// 2023-07-28 15:43:14.5210603 +0200 CEST m=+0.013058501
|
||||
// 2023-07-28 22:49:03.8541587 +0200 CEST m=+0.094140401
|
||||
package generic
|
||||
|
||||
|
||||
|
@@ -15,7 +15,7 @@
|
||||
|
||||
// Code generated by go generate; DO NOT EDIT.
|
||||
// This file was generated by robots at
|
||||
// 2023-07-28 15:43:17.2891664 +0200 CEST m=+0.022524801
|
||||
// 2023-07-28 22:49:06.6236747 +0200 CEST m=+0.039283301
|
||||
package option
|
||||
|
||||
|
||||
|
@@ -15,7 +15,7 @@
|
||||
|
||||
// Code generated by go generate; DO NOT EDIT.
|
||||
// This file was generated by robots at
|
||||
// 2023-07-28 15:43:24.9416992 +0200 CEST m=+0.030259001
|
||||
// 2023-07-28 22:49:14.4173227 +0200 CEST m=+0.013163201
|
||||
package reader
|
||||
|
||||
|
||||
|
@@ -15,7 +15,7 @@
|
||||
|
||||
// Code generated by go generate; DO NOT EDIT.
|
||||
// This file was generated by robots at
|
||||
// 2023-07-28 15:43:24.9574807 +0200 CEST m=+0.046040501
|
||||
// 2023-07-28 22:49:14.4173227 +0200 CEST m=+0.013163201
|
||||
package generic
|
||||
|
||||
|
||||
|
@@ -15,7 +15,7 @@
|
||||
|
||||
// Code generated by go generate; DO NOT EDIT.
|
||||
// This file was generated by robots at
|
||||
// 2023-07-28 15:43:27.7019865 +0200 CEST m=+0.066240401
|
||||
// 2023-07-28 22:49:16.5272334 +0200 CEST m=+0.043108701
|
||||
package readerioeither
|
||||
|
||||
|
||||
|
@@ -15,7 +15,7 @@
|
||||
|
||||
// Code generated by go generate; DO NOT EDIT.
|
||||
// This file was generated by robots at
|
||||
// 2023-07-28 15:43:27.7039855 +0200 CEST m=+0.068239401
|
||||
// 2023-07-28 22:49:16.5292332 +0200 CEST m=+0.045108501
|
||||
package generic
|
||||
|
||||
|
||||
|
@@ -15,7 +15,7 @@
|
||||
|
||||
// Code generated by go generate; DO NOT EDIT.
|
||||
// This file was generated by robots at
|
||||
// 2023-07-28 15:43:31.1018593 +0200 CEST m=+0.128090501
|
||||
// 2023-07-28 22:49:18.7141124 +0200 CEST m=+0.109464201
|
||||
package tuple
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user