New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

github.com/justenwalker/ez

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/justenwalker/ez

  • v0.0.0-20241106212936-5b8499fc0829
  • Source
  • Go
  • Socket score

Version published
Created
Source

ez

ez makes it easy to chain together stream operations.

This library declares a Stream interface and implementations for finite, infinite sequences, as well as slices.

Usage

Convert a Seq or a Slice to a Stream

// Create an infinite stream of values
fibonacci := ez.InfiniteStream(func(yield func(int) bool) {
    a := 0
    if !yield(a) {
        return
    }
    b := 1
    for yield(b) {
        a, b = b, b+a
    }
})

// or create a finite stream
oneToTen := ez.FiniteStream(func(yield func(int) bool) {
    for i := range 10 {
        if !yield(i + 1) {
            return
        }
    }
})

// or convert a slice to a stream
sliceStream := ez.SliceStream([]int{1, 2, 3, 4, 5, 6, 7})

// Pipe stream operations together with the `Pipe` function
intStream := ez.Pipe(fibonacci,
    ez.Filter(func(i int) bool { return i > 5 }),
    ez.Map(func(i int) int { return i / 2 }),
    ez.Skip[int](10),
    ez.Take[int](10),
    ez.Reverse[int],
)

// Convert from a stream of one type to another
float64Stream := ez.Convert(intStream, func(i int) float64 {
    return math.Round(math.Sqrt(float64(i)))
})

// Collect values into a slice from a Finite Stream.
values := ez.Collect(float64Stream)

// Concatenate several streams together:
concat := ez.Concat(
    oneToTen,
    sliceStream,
    ez.Pipe(fibonacci, ez.Take[int](10)),
)

// Reduce a stream to a single value
sum := ez.Reduce(concat, 0, func(acc int, v int) int { return acc + v })

FAQs

Package last updated on 06 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc