Skip to content

Instantly share code, notes, and snippets.

View omar-3's full-sized avatar
🔫

Omar omar-3

🔫
View GitHub Profile
@omar-3
omar-3 / example6Chain.chpl
Last active March 29, 2020 02:53
implementation of python's chain() method in Chapel
use RangeChunk;
iter compress(array, trutharray) {
for (i,j) in zip(array, trutharray) {
if j {
yield i;
}
}
}
@omar-3
omar-3 / example7Dropwhile.chpl
Created March 29, 2020 03:17
Implementation of python's dropwhile() method in chapel
use RangeChunk;
use Time;
iter dropwhile(array, function) {
var iterable = array;
var barrier = false;
for i in iterable {
if function(i){
barrier = true;
}
@omar-3
omar-3 / example8Filter.chpl
Created March 29, 2020 03:50
this is an implementation for python's filter method in Chapel
use RangeChunk;
use Time;
iter filter(array, function) {
for i in array {
if function(i) {
yield i;
}
}
}
@omar-3
omar-3 / example9Starmap.chpl
Created March 29, 2020 04:16
this is an implementation for python's starmap method in Chapel
use RangeChunk;
use Time;
// serial
iter starmap(array, function) {
var iterable = array; // I know that I don't need to copy "array" to new variable "iterable"
for i in iterable {
yield function((...i));
@omar-3
omar-3 / example10Groupby.chpl
Last active April 5, 2020 07:23
this is an example of python's groupby function in Chapel with 2 using cases
// this method would be super cool in databases for example in a world without GROUP BY sql command :D
use Set;
use List;
use RangeChunk;
// takes iterable of object or any stuff
// function is the thing that is common between multiple
// of some objects in iterable
@omar-3
omar-3 / example10Pipe.chpl
Last active April 1, 2020 02:59
implementation of toolz's pipe method in Chapel
proc notAdd(a: int, b: int) {
return (a + b , a + b);
}
proc notMul(a: int, b: int) {
return (a*b , a*b);
}
var h = [notAdd, notMul, notAdd, notMul, notAdd];
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.