Giter Site home page Giter Site logo

pony-shoe's Introduction

Pony Shoe Ʊ

logo.jpg

!This is just my scratch!

Note, Generic parameters are omitted from the example

Basic

Seqx.is_all([2; 4; 6], Num~is_enev())
true

Seqx.is_all([2; 3; 4], Num~is_enev())
false

Seqx.is_all([], Num~gt(0))
true

Seqx.is_any([2; 4; 6], Num~is_odd())
false

Seqx.is_any([2; 3; 4], Num~is_odd())
true

Seqx.is_any([], Num~gt(0))
false

Seqx.is_empty([])
true

Seqx.is_empty([1; 2; 3])
false

Seqx.is_member([1; 2; 3; 4; 5; 6], 5)
true

Seqx.is_member([1; 2; 3; 4; 5; 6], 7)
false

Mapping

Seqs.each(["some"; "example"], {(x: String) => print(x)})
"some"
"example"

Seqs.each(["a"; "b"], {(i: USize, x: String) => print(i.string()+"> "+x)})
"0> a"
"1> b"

Seqs.each(["apple"; "orange"], {(x: String) => print(x)}, 2)
"apple"
"orange"
"apple"
"orange"

Seqx.map([1; 2; 3], {(x: I32): I32 => x * 2})
[2; 4; 6]

Seqx.map([1; 2; 3], Num~mul(2))
[2; 4; 6]

Seqx.map([1; 2; 3], Num~mul(2), 2)
[4; 8; 12]

Seqx.map([1; 2; 3; 4; 5], {(i: USize, x: I32): I32 => x * x})
[1; 4; 9, 16, 25]

Seqx.map([1; 2; 3; 4; 5], Num~sqr())
[1; 4; 9, 16, 25]

Seqx.scan([1; 2; 3; 4; 5], Num~add())
[1; 3; 6; 10; 15]

Seqx.scan([1; 2; 3; 4; 5], {(prev: I32, curr: I32): I32 => prev*curr })
[1; 3; 6; 10; 15]

Seqx.stair(['a'; 'b'; 'c'], {(x: I32) => print(x)})
'a'
'a' 'a'
'c' 'c' 'c'

Seqs.table(["name"], ["lucy", "lily"], {(col: String, row: String) => print(col+":"+row) })
"name:lucy"
"name:lily"

let f = {(col: I32, row: I32) => print(col*row) }
Seqx.table(Num.range_i(1,3), Num.range_i(1,3), f)
1 2 3
2 4 6
3 6 9

Seqx.matix([Num.range_i(1,9), Num.range_i(1,9)], Num.range_i(1,9)], f)
...

Seqx.skip([1; 2; 3; 4; 5; 6; 7], 1, {(x: I32) => print(x.string())})
"1"
"3"
"5"
"7"

Seqx.skip([1; 2; 3; 4; 5; 6; 7], 2, {(i: USize, x: I32) => print(i.string()+":"+x.string())})
"0:1"
"3:4"
"6:7"

Folding

Seqx.scan([1; 2; 3; 4; 5], {(prev: I32, curr: I32): I32 => prev+curr })
[1; 3; 6; 10; 15]

Seqx.scan([1; 2; 3; 4; 5], Num~add())
[1; 3; 6; 10; 15]

Seqx.reduce([1; 2; 3], 0, {(x: I32, acc: I32):I32 => x + acc})
6

map_reduce([1; 2; 3], 0, {(x: I32, acc: I32): I32 => (x * 2, x + acc)})
([2; 4; 6], 6)

Filter

Seqx.filter([1; 2; 3], Num~is_enev())
[2]

Seqx.reject([1; 2; 3], {(x:I32): I32 => x%%2 == 0})
[1; 3]

Seqx.take([1; 2; 3], 2)
[1; 2]

Seqx.take_random(Num.range_i(1, 10), 2)
[7; 2]

Seqx.dedup([1; 2; 3; 3; 2; 1])
[1; 2; 3; 2; 1]

Seqx.dedup_by([(1, "a"), (2, "b"), (2, "c"), (1, "a")], {(x: B): Any => x._1})
[(1, "a"), (2, "b"), (1, "a")]

Seqx.drop([1; 2; 3], 2)
[3]

Seqx.drop([1; 2; 3], -1)
[1; 2]

Seqx.uniq([1, 5, 3, 3, 2, 3, 1, 5, 4])
[1, 5, 3, 2, 4]

Aggregate

Seqx.count([1; 2; 3; 4; 5; 6])
6

Seqx.count_by([1; 2; 3; 4; 5; 6], Num~gt(3))
3

Seqx.sum([1; 2; 3])
6

Seqs.sum_by(["1"; "2"; "3"], Str~join(":"))
"1:2:3"

Seqx.min([5; 6; 7; 3; 1; 2])
1

Seqx.max([5; 6; 7; 3; 1; 2])
7

Seqx.min_max([5; 6; 7; 3; 1; 2]
(1, 7)

Seqx.first([1; 2; 3; 4; 5; 6])
1

Seqx.second([1; 2; 3; 4; 5; 6])
2

Seqx.at([1; 2; 3; 4; 5; 6], 3)
4

Seqx.head([1; 2; 3; 4; 5; 6])
[1]

Seqx.tail([1; 2; 3; 4; 5; 6])
[2; 3; 4; 5; 6]

Seqx.slice([0; 1; 2; 3; 4; 5; 6; 7; 8; 9], 5, 20)
[5; 6; 7; 8; 9]

Seqx.slice([0; 1; 2; 3; 4; 5; 6; 7; 8; 9], -3, 2)
[7; 8]

Sort

Seqx.swap([2; 3; 1; 5], 0, 2)
[1; 3; 2; 5]

Seqx.reverse([1; 2; 3])
[3; 2; 1]

Seqx.sort([2; 3; 1])
[1; 2; 3]

Seqx.sort_by(["some"; "kind"; "of"; "monster"], {(x: String): USize => x.size()})
["of"; "some"; "kind"; "monster"]

Seqx.sort_by(["some"; "kind"; "of"; "monster"], Str~size())
["of"; "some"; "kind"; "monster"]

Seqx.shuffle([1; 2; 3; 4; 5])
[3; 1; 4; 2; 5]

Seqx.rotation([1; 2; 3; 4; 5; 6; 7], 1)
[7; 1; 2; 3; 4; 5; 6]

Seqx.rotation({1, 2, 3, 4, 5, 6, 7}, 2)
{6, 7, 1, 2, 3, 4, 5}

Split

Seqx.chunk_by([1; 2; 2; 3; 4; 4; 6; 7; 7], Num.is_is_odd())
[[1]; [2; 2]; [3]; [4; 4; 6]; [7; 7]]

Seqx.chunk_every([1; 2; 3; 4; 5; 6], 2)
[[1; 2]; [3; 4]; [5; 6]]

Seqx.split([1, 2, 3], 2)
[[1; 2]; [3]]

Merge

Seqx.merge([1; 2; 3], [4; 5; 6; 7])
[1; 2; 3; 4; 5; 6; 7]

Seqx.concat([[1; 2; 3]; [4; 5; 6]; [7; 8; 9])
[1; 2; 3; 4; 5; 6; 7; 8; 9]

Seqx.join([1; 2; 3])
"123"

Seqx.join([1; 2; 3], " = ")
"1 = 2 = 3"

Seqx.map_join([1; 2; 3], "", Num~mul(2))
"246"

Seqx.map_join([1; 2; 3], " = ", Num~mul(2))
"2 = 4 = 6"

Convert

Seqx.to_list([1; 2; 3])
{1, 2, 3}

Seqx.to_array({1, 2, 3})
[1; 2; 3]

Seqx.flat_map(['a', 'b', 'c'], {(x: U8): Array[Any] => [x; x]})
['a'; 'a'; 'b'; 'b'; 'c'; 'c']

Seqx.flat_map(['a', 'b', 'c'], Num~copy())
['a'; 'a'; 'b'; 'b'; 'c'; 'c']

Seqx.flat_map(['a', 'b', 'c'], Num~copy(2))
['a'; 'a'; 'a'; 'b'; 'b'; 'b'; 'c'; 'c'; 'c']

Seqx.intersperse([1; 2; 3], 0)
[1; 0; 2; 0; 3]

Seqx[Array[String], String].with_index(["a"; "b"; "c"])
[("a", 0); ("b", 1); ("c", 2)]

Seqx.zip([[1; 2; 3]; ['a'; 'b'; 'c']; ["foo"; "bar"; "baz"]])
[(1, 'a', "foo"); (2, 'b', "bar"); (3, 'c', "baz")]

Seqx.zip({[1; 2; 3; 4; 5], ['a'; 'b'; 'c']})
[(1, 'a'); (2, 'b'); (3, 'c')]

Seqx.unzip([("a", 1); ("b", 2); ("c", 3)])
[["a"; "b"; "c"]; [1; 2; 3]]

Seqx.unzip([["a"; 1]; ["b"; 2]; ["c"; 3}]])
[["a"; "b"; "c"]; [1; 2; 3]]

let m = Map[String, ISize]
Seqs.into(["a"; 1; "b"; 2], m)
<"a": 1, "b": 2>

let m2 = Map[String, ISize]
m2("b")= 2
Seqs.into(%{a: 1}, m2)
<"a": 1, "b": 2>

let m3 = Map[String, ISize]
Seqs.into(["a": 1, "a": 2], m3)
<"a": 2>

let set = Set[ISize]
Seqs.into([1; 2], set)
<1, 2>

More

seqs.pony

pony-shoe's People

Contributors

damon-kwok avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.