evilsoft / crocks

A collection of well known Algebraic Data Types for your utter enjoyment.
https://crocks.dev
ISC License
1.59k stars 102 forks source link

Add maybeToList and maybeToArray transformations #412

Closed evilsoft closed 5 years ago

evilsoft commented 5 years ago

Just two handy Transformers...well Transformations...

image

When working through a couple example of how to filter and transform without using reduce on Arrays and Lists, I found that a lot of value could be adding with some maybeToX transformations. The basically will take a Maybe to either a List or an Array. A Just instance will return a single element structure, containing the value in the original Just. While a Nothing returns an empty structure.

When used with chain this can be used to filter and transform a structures values in one go, without having to set up a mapReduce with alt to get the same result.

In addition to adding these functions and their documentation, Also added a couple links to the Result NTs and cleaned up some specs that suffered from :policeman:-y :spaghetti: artifacts.

coveralls commented 5 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling 17a85ff990bc5714fb412aa89ba4d313fcc60998 on feat/maybe-list-nt into fb312d870580809a8aaf335185960f80785c3d10 on master.

coveralls commented 5 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling c839a5d456b9656af87269dd9bd59189597847e2 on feat/maybe-list-nt into fb312d870580809a8aaf335185960f80785c3d10 on master.

evilsoft commented 5 years ago

image