Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-merge 'devel' into 'master'. #22

Merged
merged 25 commits into from
Jun 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
fa23184
Merge branch 'devel' of https://github.com/thenjip/nim-iterator-strea…
thenjip Dec 15, 2019
01c05e0
Merge branch 'devel' of https://github.com/thenjip/nim-iterator-strea…
thenjip Dec 21, 2019
e6907e8
Merge branch 'devel' of https://github.com/thenjip/nim-iterator-strea…
thenjip Dec 21, 2019
61b7768
Run all the modules containing a main.
thenjip Dec 28, 2019
540878a
Fix the path of the executed module in Nimble file's test target.
thenjip Dec 28, 2019
5958d3a
Print the command line currently executed on the console when running…
thenjip Dec 28, 2019
4c6d302
Add a test suite to all the modules.
thenjip Dec 28, 2019
fab52d1
Merge pull request #10 from thenjip/f_execute_all_tests
thenjip Dec 28, 2019
e75dc03
Merge branch 'devel' of https://github.com/thenjip/nim-iterator-strea…
thenjip Dec 28, 2019
76ee6ee
Implement the IO monad. (#12)
thenjip Jan 5, 2020
2e4da80
Merge branch 'devel' of https://github.com/thenjip/nim-iterator-strea…
thenjip Jan 5, 2020
2d40e05
Merge branch 'master' into devel
thenjip Jan 5, 2020
c805b97
Merge branch 'devel' of https://github.com/thenjip/nim-iterator-strea…
thenjip Jan 5, 2020
c28d0de
Merge branch 'master' of https://github.com/thenjip/nim-iterator-stre…
thenjip Jan 5, 2020
91c7726
Implement the "close" event for a stream. (#14)
thenjip May 14, 2020
421921d
Merge branch 'devel' of https://github.com/thenjip/nim-iterator-strea…
thenjip May 14, 2020
7638ca4
Add an alias to "() =>". (#16)
thenjip May 14, 2020
8d3439c
Merge branch 'devel' of https://github.com/thenjip/nim-iterator-strea…
thenjip May 14, 2020
3815ace
Merge branch 'master' into devel
thenjip May 14, 2020
8fa5932
Delete "./chain" and "./io".
thenjip May 14, 2020
4f086b8
Add more tests. (#18)
thenjip Jun 19, 2020
cd0dd8d
- monad/optional: (#20)
thenjip Jun 20, 2020
a634eb5
Merge branch 'master' of https://github.com/thenjip/nim-iterator-stre…
thenjip Jun 20, 2020
1f9e74d
Merge branch 'master' into devel.
thenjip Jun 20, 2020
73686d9
Add and improve tests. (#19) (#21)
thenjip Jun 20, 2020
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
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
.nimcache/
nimcache/
nimblecache/
htmldocs/
35 changes: 29 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,38 @@ language: c

os: linux
dist: bionic

sudo: required

services:
- docker

before_install:
- docker pull nimlang/nim

script:
- docker run nimlang/nim nim --version
- docker run -v "$(pwd):/project" -w /project nimlang/nim sh -c "nimble install -dy && nimble test"
env:
global:
- DOCKER_IMG='nimlang/nim:latest-alpine'


_shared_job: &shared_job
before_install:
- docker pull "$DOCKER_IMG"
script:
- docker run "$DOCKER_IMG" nim --version
- docker run -v "$(pwd):/project" -w /project -e NIM_BACKEND="$NIM_BACKEND" "$DOCKER_IMG" sh -c "nimble install -dy && nimble test"


jobs:
include:
- name: Test suite (C)
env: NIM_BACKEND='cc'
<<: *shared_job

- name: Test suite (C++)
env: NIM_BACKEND='cpp'
<<: *shared_job

- name: Test suite (Node.js)
env: NIM_BACKEND='js'
<<: *shared_job

allow_failures:
- env: NIM_BACKEND='js'
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# nim-iterator-stream-experiment

An attempt at providing a replacement for iterators in Nim with an API similar to Java 8 Stream.
163 changes: 143 additions & 20 deletions nim_iterator_stream_experiment.nimble
Original file line number Diff line number Diff line change
@@ -1,32 +1,155 @@
# Package
version = "0.1.0"
author = "thenjip"
description = "An attempt at providing a replacement for closure iterators in Nim with an API similar to Java 8 Stream."
license = "MIT"
srcDir = "src"

version = "0.1.0"
author = "thenjip"
description = "An attempt at providing a replacement for closure iterators in Nim with an API similar to Java 8 Stream."
license = "MIT"
srcDir = "src"
requires "nim >= 1.2.0"



# Dependencies
import std/[options, os, sequtils, strformat, strutils, sugar]



type
AbsolutePath = string
RelativePath = string

Backend {.pure.} = enum
C
Cxx
Js

InvalidEnvVarValueError = object of CatchableError



func newInvalidEnvVarValueError (
name: string;
value: string
): ref InvalidEnvVarValueError =
InvalidEnvVarValueError.newException(fmt"""{name}="{value}"""")


func findFirst [I, T](a: array[I, T]; predicate: I -> bool): Option[I] =
result = I.none()

for i, item in a:
if i.predicate():
return i.some()



func projectName (): string =
const name = "nim_iterator_stream_experiment"

name



proc moduleDir (): RelativePath =
srcDir / projectName()


func nimcacheDirName (): string =
const name = ".nimcache"

name


func nimcacheDir (): AbsolutePath =
const dir = projectDir() / nimcacheDirName()

dir

requires "nim >= 1.2.0"


func backendEnvVarName (): string =
const name = "NIM_BACKEND"

import std/[os, sequtils, strformat, strutils]
name


func nimCmdNames (): array[Backend, string] =
const names = ["cc", "cpp", "js"]

task test, "":
withDir srcDir:
names


func nimCmdName (backend: Backend): string =
nimCmdNames()[backend]


proc readBackendFromEnv (): Option[Backend] {.
raises: [InvalidEnvVarValueError, ValueError]
.} =
let envVarName = backendEnvVarName()

if envVarName.existsEnv():
let
projectName = "nim_iterator_stream_experiment"
cmdElements =
[
"c",
"-r",
projectDir() / srcDir / fmt"{projectName}{ExtSep}nim"
]

cmdElements.foldl([a, b.quoteShell()].join($' '), "").selfExec()
envVarValue = envVarName.getEnv()
backendFound = nimCmdNames().findFirst(b => b.nimCmdName() == envVarValue)

if backendFound.isSome():
backendFound
else:
raise newInvalidEnvVarValueError(envVarName, envVarValue)
else:
Backend.none()



func testTaskDescription (): string =
func backendChoice (): string =
nimCmdNames().`@`().foldl(a & '|' & b)

@[
fmt"""Build the test suite in "{nimcacheDir()}{DirSep}" and run it.""",
fmt"""The backend can be specified in the environment variable "{backendEnvVarName()}=({backendChoice()})"."""
].foldl(a & ' ' & b)



task test, testTaskDescription():
func buildGenDir (module: RelativePath; backend: Backend): AbsolutePath =
let (dir, file) = module.splitPath()

nimcacheDir() / backend.nimCmdName() / dir / file


proc buildCmdLineParts (
module: RelativePath;
backendSupplier: () -> Option[Backend]
): seq[string] =
func handleJsFlags (backend: Backend): seq[string] =
if backend == Backend.Js:
@["-d:nodejs"]
else:
@[]

let
backend = backendSupplier().get(Backend.C)
genDir = module.buildGenDir(backend).quoteShell()
nimCmd = backend.nimCmdName()
shortOptions = @["-r"] & backend.handleJsFlags()
longOptions = @[fmt"--nimcache:{genDir}", fmt"--outdir:{genDir}"]

@[nimCmd].concat(shortOptions, longOptions, @[module])


withDir moduleDir():
for file in system.getCurrentDir().walkDirRec(relative = true):
if file.endsWith(fmt"{ExtSep}nim"):
file
.buildCmdLineParts(readBackendFromEnv)
.foldl(a & $' ' & b.quoteShell())
.selfExec()



task clean_test, """Remove the build directory of the "test" task.""":
let buildDir = nimcacheDir()

if system.existsDir(buildDir):
buildDir.rmDir()
24 changes: 0 additions & 24 deletions src/nim_iterator_stream_experiment.nim

This file was deleted.

Loading