Getting started

Welcome! We are excited that you want to know about Koazee. The Koazee Getting started will guide you to get your project ready.

What is Koazee?

Koazee is a handy Golang library focused on helping developers and make their life easier by taking the hassle out of working with arrays. It takes an array and creates an stream. The stream can be easily manipulated by making use of the provided operations by Koazee.

Koazee is inspired in two of the most powerful, and well-known, techniques in Software development.

Lazy evaluation: Your stream operations will only be performed when required.

  • Don't evaluate unnecessary code
  • Do the things when they need to be done!

Functional programming: It helps us to write better code.

  • It allows you to write more compressed and predictable code.
  • It’s easier to test.

How does Koazee work?

Koazee takes advantage of reflection and simplify the way to deal with arrays. It provides us with a great and growing set of powerful operations over arrays.

The full list of available operations can be found on Koazee Documentation

Installing

Add Koazee to your project


    module github.com/me/project
    require ( 
        github.com/wesovilabs/koazee vX.Y.Z
    )
    glide get github.com/wesovilabs/koazee
    go get github.com/wesovilabs/koazee

Usage

Once Koazee is added to the project you just need to import it

    
    package main
    
    import (
        "fmt"
        "github.com/wesovilabs/koazee"
    )
    
    var numbers = []int{1, 3, 5, 7, 9}
    var lowerThan5 = func(val int) bool { return val < 5 }
    var duplicate = func(val int) int { return val * 2 }
    var sum = func(acc, value int) int { return acc + value }
    
    func main() {
    
        result := koazee.StreamOf(numbers).
            Filter(lowerThan5).
            Map(duplicate).
            Add(2).
            Reduce(sum).
            Int()
            
        fmt.Printf("Result is %d\n", result)
    }


As a friend of mine says: “Developoing is like writing poetry”, and the above code looks like that

Stream operations

The list of already implemented operations is below, much more are comming soon!

Name Description
Out Obtain the stream content: The current array and the error
With Load or replace the elements in the stream
Add Add a new element into the stream. Documentation
Drop Drop an existing element in the stream Documentation
First Obtain the first element in the stream Documentation
Last Obtain the last element in the stream Documentation
At Obtain the element in the stream that is in the given position Documentation
Contains Check if an element is found in the stream Documentation
Count Return the number of elements in the stream Documentation
Filter Discard those elements in the stream that do not match with the given conditions Documentation
Reduce Return the result after applying the provided function over all the items in the stream Documentation
Map Convert the current elements in the stream into a different type Documentation
ForEach Do something over all the elements in the stream Documentation
Sort Sort the elements in the stream Documentation
RemoveDuplicates Remove duplicates elements in the stream Documentation
Compose Join 2 or more streams in a single one Documentation
Have a look at Koazee Documentation to learn more.