Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@

The library uses [semantic versions](http://semver.org) to identify stable releases.

## Release 4.6.x

**Features**
* [#68](https://github.com/fogfish/datum/issues/68): Implements generic representations
* Support product lenses for records (`lens:p/1`).


## Release 4.5.x

**Features**
* [#54](https://github.com/fogfish/datum/issues/54): Implements pattern matching within do-notation
* Add typecast utility for scalar types.
* Support MFA generator for streams
* implements lens isomorphism (`lens:iso/2`, `lens:iso/4`) and product lens (`lens:p/1`).

**Improvements**

* Support lists comprehension at do-notation

## Release 4.4.0

**Features**
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright 2012 Dmitry Kolesnikov

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
10 changes: 1 addition & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
##
## @doc
## an example Makefile to build and ship erlang software
##
## APP - identity of the application
## ORG - identity of the organization
## URI - identity of the docker repository with last /

APP = datum
ORG = fogfish
URI =

include erlang.mk
include beam.mk

35 changes: 18 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@

The [feature overview](doc/features.md) provides an introduction to datum features, use-cases and reasoning of they existence:

* data structures with common behavior: **foldable**, **traversable** and **map-like** including
* pure functional **data types**: binary search tree, red-black tree, heap, queues, streams and others
* `option` and `either` type notations
* a set of generic data types that can be inspected, traversed, and manipulated with common behavior: **foldable**, **traversable** and **map-like**.
* pure functional **data types**: binary search tree, red-black tree, heap, queues, and others
* **streams** or lazy lists are a sequential data structure that contains on demand computed elements.
* resembles concept of getters and setters ([**lens**](doc/lens.md)) for complex algebraic data types.
* define a **category pattern**, **monads** and **do-notation** with pattern matching
* [type casts](doc/typecast.md) of scalar (primitive) data types
* mapping of algebraic data types to they [**generic**](doc/generic.md) representation and back
* define a [**category pattern**](doc/category.md), [**monads**](doc/monad.md) and they composition for Erlang applications. You might be familiar with this concept as pipe, flow or function composition.
* generic [**do-notation**](doc/monad.md) with pattern matching.
* [**typecasts**](doc/typecast.md) of primitive data types
* supports **OTP/18.x** or later release


**Cheat Sheet** is available [here](doc/cheatsheet.md)

## Getting started

The latest version of the library is available at its `master` branch. All development, including new features and bug fixes, take place on the `master` branch using forking and pull requests as described in contribution guidelines.
Expand All @@ -37,16 +39,20 @@ The stable library release is available via hex packages, add the library as dep
{deps, [{datum}]}.
```

Please follow the [feature overview](doc/features.md) to start leaning all available features; then continue to library [examples](examples) and to [source code](src).


## How To Contribute

The library is Apache 2.0 licensed and accepts contributions via GitHub pull requests:
The library is [Apache 2.0](LICENSE) licensed and accepts contributions via GitHub pull requests:

* Fork the repository on GitHub
* Read build instructions
* Make a pull request
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Added some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request

The build process requires [Erlang/OTP](http://www.erlang.org/downloads) version 19.0 or later and essential build tools.
The development requires [Erlang/OTP](http://www.erlang.org/downloads) version 19.0 or later and essential build tools.

**Build** and **run** service in your development console. The following command boots Erlang virtual machine and opens Erlang shell.

Expand Down Expand Up @@ -89,9 +95,4 @@ If you experience any issues with the library, please let us know via [GitHub is

## License

Copyright 2012 Dmitry Kolesnikov

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

[![See LICENSE](https://img.shields.io/hexpm/l/plug.svg?style=for-the-badge)](LICENSE)
37 changes: 23 additions & 14 deletions erlang.mk → beam.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
## @doc
## This makefile is the wrapper of rebar to build and ship erlang software
##
## @version 1.0.9
## @version 1.0.12
.PHONY: all compile test unit clean distclean run console mock-up mock-rm benchmark release dist

APP := $(strip $(APP))
Expand All @@ -27,13 +27,13 @@ REL = ${APP}-${VSN}
PKG = ${REL}+${ARCH}.${PLAT}
TEST ?= tests
COOKIE ?= nocookie
DOCKER ?= fogfish/erlang
DOCKER ?= fogfish/erlang-alpine
IID = ${URI}${ORG}/${APP}

## required tools
## - rebar version (no spaces at end)
## - path to basho benchmark
REBAR ?= 3.5.0
REBAR ?= 3.9.1
BB = ../basho_bench


Expand Down Expand Up @@ -89,17 +89,23 @@ compile: rebar3

##
## execute common test and terminate node
test: _build/test.beam
@mkdir -p /tmp/test/${APP}
@erl ${EFLAGS} -noshell -pa _build/ -pa test/ -run test run test/${TEST}.config
@F=`ls /tmp/test/${APP}/ct_run*/all.coverdata | tail -n 1` ;\
cp $$F /tmp/test/${APP}/ct.coverdata

_build/test.beam: _build/test.erl
@erlc -o _build $<

_build/test.erl:
@mkdir -p _build && echo "${BOOT_CT}" > $@
test:
# @./rebar3 ct --config test/${TEST}.config --cover --verbose
@./rebar3 ct --cover --verbose
@./rebar3 cover

# test: _build/test.beam
# @mkdir -p /tmp/test/${APP}
# @erl ${EFLAGS} -noshell -pa _build/ -pa test/ -run test run test/${TEST}.config
# @F=`ls /tmp/test/${APP}/ct_run*/all.coverdata | tail -n 1` ;\
# cp $$F /tmp/test/${APP}/ct.coverdata
#
# _build/test.beam: _build/test.erl
# @erlc -o _build $<
#
# _build/test.erl:
# @mkdir -p _build && echo "${BOOT_CT}" > $@
#

testclean:
@rm -f _build/test.beam
Expand Down Expand Up @@ -148,6 +154,7 @@ mock-rm: test/mock/docker-compose.yml
-@docker-compose -f $< down --rmi all -v --remove-orphans

dist-up: docker-compose.yml _build/spawner
@docker-compose build
@docker-compose -f $< up

dist-rm: docker-compose.yml
Expand Down Expand Up @@ -191,6 +198,8 @@ endif

## build docker image
docker: Dockerfile
git status --porcelain
test -z "`git status --porcelain`" || exit -1
docker build \
--build-arg APP=${APP} \
--build-arg VSN=${VSN} \
Expand Down
31 changes: 0 additions & 31 deletions doc/cheatsheet.md

This file was deleted.

31 changes: 31 additions & 0 deletions doc/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* [Pure functional data types](#pure-functional-data-types)
* [Stream](#stream)
* [Lens](#lens)
* [Generic representation](#generic-representation)
* [Category pattern](#category-pattern)
* [Monad](#monad)

Expand Down Expand Up @@ -204,6 +205,36 @@ end.
lens:get(Lens(a), lens:put(Lens(a), 1, bst:new())).
```

## Generic representation

Automatic transformation of algebraic data types to they generic representation solve wide problems of generic programming. Erlang has strong foundation and language primitives on this aspect due to dynamically typed nature. Existence of generic types (lists, maps and tuples) makes a programming task trivial. However, absence of strong types makes it error prone while switching a context from generic algorithms to business domain. Thus usage of algebraic data types (encoded in Erlang records) improves maintainability of domain specific code.

> The main advantage of using records rather than tuples is that fields in a record are accessed by name, whereas fields in a tuple are accessed by position.

The library introduces a `generic` parse transform that implements automatic mapping between ADTs and generic representations.

```erlang
-compile({parse_transform, generic}).

-record(person, {name, address, city}).

example() ->
%%
%% builds a generic representation from #person{} ADT
Gen = generic_of:person(#person{
name = "Verner Pleishner",
address = "Blumenstrasse 14",
city = "Berne"
}),

%%
%% builds #person{} ADT from generic representation
generic_to:person(Gen).
```

In facts, a macro magic happens behind to execute transformation without boilerplate. As the result a labeled generic representation is returned.

See details about [generic patterns](generic.md).


## Category pattern
Expand Down
Loading