Add mapf for map functions

This commit is contained in:
rwxrob 2022-02-26 20:39:33 -05:00
parent d1cb39cdac
commit e38023c38c
No known key found for this signature in database
GPG Key ID: 2B9111F33082AE77
2 changed files with 23 additions and 0 deletions

10
mapf/mapf.go Normal file
View File

@ -0,0 +1,10 @@
/*
Package mapf contains nothing but map functions suitable for use with
the fn.Map generic function or the equivalent fn.A method. See the maps
package for functions that accept entire generic slices to be
transformed with mapf (or other) functions.
*/
package mapf
// HashComment adds a "# " prefix.
func HashComment(i string) string { return "# " + i }

13
mapf/mapf_test.go Normal file
View File

@ -0,0 +1,13 @@
package mapf_test
import (
"github.com/rwxrob/bonzai/fn"
"github.com/rwxrob/bonzai/mapf"
)
func ExampleHashComment() {
fn.A[string]{"foo", "bar"}.M(mapf.HashComment).P()
// Output:
// # foo
// # bar
}