npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rentgen

v0.1.2

Published

A ReasonML generator library, designed for Deno and Node

Downloads

1

Readme

Rentgen

A ReasonML generator library

Goals

  1. Uses an open api, which allows for the usage of fully in-reason generators, as well as external ones.
  2. Handling of sync and async generators.
  3. Written fully in Reason.

Documentation

Most of the documentation, together with examples, can be found inline

Sync


type next('a)

Represents the next value yielded by a generator

type gen('a)

Represents the api of a generator

next : gen('a) => next('a)

Increments the generator given, and returns its next) value.

return : (gen('a), 'a) => next('a)

Forces the generator to return the 2nd argument and stop.

throw : (gen('a), Js.Exn.t) => next('a)

Throws the error in the generator and forces it to stop.

from : 'a => gen('b)

Creates a generator from an external source, which implements the javascript generator api.

range : (~to_: int, ~from=0 : int, ~step=1 : int) => gen(int)

Creates a generator returning numbers from the range <from; to_> separated by the distance of step. Creates an int range.

range(~to_=10)->foldl((+), 0)
// => 55

from_list : list('a) => gen('a)

Converts a list to a generator.

[1,2,3]->from_list->foldl((+), 0)
// => 6

inf : 'a => ('a => 'a) => gen('a)

Creates an infinite generator from an initial value and a successor function.

inf(0, a => a + 1) // => <0, 1, 2, 3, ...>

map : (gen('a), ('a => 'b)) => gen('b)

Transforms the values of a generator.

range(~to_=5, ()) -> map(a => a * 2)
// => <0, 2, 4, 6, 8, 10>

keep : (gen('a), ('a => bool)) => gen('a)

Returns only the values of the generator which match the function.

range(~to_=10, ()) -> keep(a => a mod 2 == 0)
// => <0, 2, 4, 6, 8, 10>

consume : (gen('a), 'a => 'b) => unit

Consumes a generator with a function.

// prints an infinite generator
inf(0, a => a + 1) -> consume(Js.Console.log)
// 0
// 1
// 2 ...
// => unit

foldl : (gen('a), (('b, 'a) => 'b), 'b) => 'b

Folds a generator into a single value.

[1,2,3]->from_list->foldl((+), 0)
// => 6

foldl1 : (gen('a), ('b, 'a) => 'b) => 'b

Folds a generator into a single value, taking the first value as the initial value.

range(~to_=3, ~from=1,())
->map(float_of_int)
->foldl1((a, b) => a /. b)
// => 1/6

take : (gen('a), int) => gen('a)

Takes n values of the generator or until it ends.

inf(0, a => a + 1) -> take(5)
// => <0, 1, 2, 3, 4>

take_while : (gen('a), ('a => bool)) => gen('a)

Takes the values of the generator as long as the function returns true.

inf(0, a => a*2 + 1)->take_while(a => a < 15)
// => <0, 1, 3, 7>

Async


type async('a) = Js.Promise.t('a)

type next_async('a) = async(next('a))

type gen_async('a)

next_async : gen_async('a) => next_async('a)

Returns the next value of an async generator

return_async : (gen_async('a), 'a) => next_async('a)

Returns the value given (as a promise), and forces the generator to stop

throw_async : (gen_async('a), Js.Exn.t) => next_async('a)

Throw the given error in the generator and forces it to stop

from_async : 'a => gen_async('b)

Creates a generator from an external source, which implements the async iterator api.

from_sync : gen('a) => gen_async('a)

Converts a sync generator into an async one.

inf(1, a => a + 1)
->from_sync
->take_async(100)
->consume_async(Js.Console.log)

map_async : (gen_async('a), ('a => 'b)) => gen_async('b)

Transforms an async generator using the function given.

puppy_stream
-> map_async(pet)
// => <async("doggo_1"), async("doggo_2"), ...>

foldl_async : (gen_async('a), (('b, 'a) => 'b), 'b) => async('b)

Folds an async generetor into a single promise

open_file("data/numbers.txt")
->map_async(Js.Float.fromString)
->foldl_async((+.), 0.)
// => async(21)

foldl1_async : (gen_async('a), (('b, 'a) => 'b)) => [async('b)]

Folds an async generator into a single promise, taking the first value as the initial value.

range(~to_=3, ~from=1, ())
->map(float_of_int)
->from_sync
->foldl1_async((a, b) => a /. b)
// => async(1/6)

consume_async : (gen_async('a), 'a => 'b) => async(unit)

Consumes an async stream, and returns an empty promise.

from_async(Deno.iter(file, ()))
->consume_async(Js.Console.log)
// (prints the file)
// => async(unit)

take_async : (gen_async('a), int) => gen_async('a)

Takes the first n elements from the async generator, and returns a new one of the length n.

infinite_puppies
->take_async(5)
// => async<"puppy1", "puppy2", ... , "puppy5">

take_while_async : (gen_async('a), ('a => bool)) => gen_async('a)

Takes elements of the generator as long as the condition given is met. Returns a new async generator.

keep_async : (gen_async('a), ('a => bool)) => gen_async('a)

Returns an async generator of the items which meet the condition given.

Examples

Fizz-buzz

open Sync;

let () = inf(0, a => a + 1)
->map(a =>
   if (a mod 15 == 0) {
     "fizzbuzz";
   } else if (a mod 3 == 0) {
     "fizz";
   } else if (a mod 5 == 0) {
     "buzz";
   } else {
     Js.Int.toString(a);
   }
 )
->consume(Js.Console.log);