Code Monkey home page Code Monkey logo

lazy_for's Introduction

LazyFor Kantox ❤ OSS  Test  Dialyzer  Coverage Status

Scene in club lounge, by Thomas Rowlandson

Scene in club lounge, by Thomas Rowlandson

About

The stream-based implementation of Kernel.SpecialForms.for/1.

Has the same syntax as its ancestor, returns a stream.

Currently supports Enum.t() as an input. Examples are gracefully stolen from the ancestor’s docs.

Examples:

iex> import LazyFor
iex> # A list generator:
iex> result = stream n <- [1, 2, 3, 4], do: n * 2
iex> Enum.to_list(result)
[2, 4, 6, 8]

iex> # A comprehension with two generators
iex> result = stream x <- [1, 2], y <- [2, 3], do: x * y
iex> Enum.to_list(result)
[2, 3, 4, 6]

iex> # A comprehension with a generator and a filter
iex> result = stream n <- [1, 2, 3, 4, 5, 6], rem(n, 2) == 0, do: n
iex> Enum.to_list(result)
[2, 4, 6]

iex> users = [user: "john", admin: "meg", guest: "barbara"]
iex> result = stream {type, name} when type != :guest <- users do
...>   String.upcase(name)
...> end
iex> Enum.to_list(result)
["JOHN", "MEG"]

iex> Enum.to_list(stream <<c <- "a b c">>, c != ?\s, do: c)
'abc'

Installation

def deps do
  [
    {:lazy_for, "~> 1.0"}
  ]
end

Changelog

v1.1.0

  • reduce: optional argument is experimentally supported

v1.0.0

  • version bump

v0.3.0

  • optional arguments :into, :uniq, and :take
  • remaining: :reduce

v0.2.0

  • assignments inside the pipeline
  • support for binary comprehensions

lazy_for's People

Contributors

am-kantox avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

lazy_for's Issues

Benchmarks

Provide benchmarks to compare stream and for on:

  • short lists
  • long lists
  • long sparsed lists (like x <- 1..1_000_000, mod(x, 1_000) == 0)

Binary generator

iex> result = stream <<c <- "abc">>, do: c
iex> Enum.to_list(result)
'abc'

Bitstring generators

      iex> # Bitstring generators are also supported and are very useful
      iex> #    when you need to organize bitstring streams:
      iex> pixels = <<213, 45, 132, 64, 76, 32, 76, 0, 0, 234, 32, 15>>
      iex> result = stream <<r::8, g::8, b::8 <- pixels>>, do: {r, g, b}
      iex> Enum.to_list(result)
      [{213, 45, 132}, {64, 76, 32}, {76, 0, 0}, {234, 32, 15}]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.