Skip to content

Commit 732db42

Browse files
committed
move
0 parents  commit 732db42

23 files changed

+1288
-0
lines changed

.gitignore

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/.build/
2+
/_build/
3+
/Build
4+
/Build.bat
5+
/blib
6+
/Makefile
7+
/pm_to_blib
8+
9+
/carton.lock
10+
/.carton/
11+
/local/
12+
13+
nytprof.out
14+
nytprof/
15+
16+
cover_db/
17+
18+
*.bak
19+
*.old
20+
*~
21+
*.swp
22+
*.o
23+
*.obj
24+
25+
!LICENSE
26+
27+
/_build_params
28+
29+
MYMETA.*
30+
31+
/Scalish-*

.proverc

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--exec "perl -Ilib -It/lib -MTest::Name::FromLine"
2+
-Ietc
3+
-Ilib
4+
-It/lib
5+
--color
6+
--failures
7+
--recurse
8+
--merge
9+
--timer
10+
--trap
11+

.travis.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
language: perl
2+
sudo: false
3+
perl:
4+
- "5.12"
5+
- "5.14"
6+
- "5.16"
7+
- "5.18"
8+
- "5.20"
9+
- "5.22"
10+
- "5.24"
11+
- "5.26"
12+

Build.PL

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# =========================================================================
2+
# THIS FILE IS AUTOMATICALLY GENERATED BY MINILLA.
3+
# DO NOT EDIT DIRECTLY.
4+
# =========================================================================
5+
6+
use 5.008_001;
7+
use strict;
8+
9+
use Module::Build::Tiny 0.035;
10+
11+
Build_PL();
12+

Changes

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Revision history for Perl extension Scalish
2+
3+
{{$NEXT}}
4+
5+
- original version
6+

LICENSE

+378
Large diffs are not rendered by default.

META.json

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"abstract" : "It's new $module",
3+
"author" : [
4+
"mp0liiu <[email protected]>"
5+
],
6+
"dynamic_config" : 0,
7+
"generated_by" : "Minilla/v3.0.16, CPAN::Meta::Converter version 2.150010",
8+
"license" : [
9+
"perl_5"
10+
],
11+
"meta-spec" : {
12+
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
13+
"version" : "2"
14+
},
15+
"name" : "Scalish",
16+
"no_index" : {
17+
"directory" : [
18+
"t",
19+
"xt",
20+
"inc",
21+
"share",
22+
"eg",
23+
"examples",
24+
"author",
25+
"builder"
26+
]
27+
},
28+
"prereqs" : {
29+
"configure" : {
30+
"requires" : {
31+
"Module::Build::Tiny" : "0.035"
32+
}
33+
},
34+
"develop" : {
35+
"requires" : {
36+
"Test::CPAN::Meta" : "0",
37+
"Test::MinimumVersion::Fast" : "0.04",
38+
"Test::PAUSE::Permissions" : "0.04",
39+
"Test::Pod" : "1.41",
40+
"Test::Spellunker" : "v0.2.7"
41+
}
42+
},
43+
"runtime" : {
44+
"requires" : {
45+
"Class::Accessor::Lite" : "0.08",
46+
"Exception::Tiny" : "v0.2.1",
47+
"perl" : "5.014004"
48+
}
49+
},
50+
"test" : {
51+
"requires" : {
52+
"Test::More" : "1.302135"
53+
}
54+
}
55+
},
56+
"release_status" : "unstable",
57+
"version" : "0.01",
58+
"x_serialization_backend" : "JSON::PP version 2.27400_02"
59+
}

README.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# NAME
2+
3+
Scalish - It's new $module
4+
5+
# SYNOPSIS
6+
7+
use Scalish;
8+
9+
# DESCRIPTION
10+
11+
Scalish is ...
12+
13+
# LICENSE
14+
15+
Copyright (C) mp0liiu.
16+
17+
This library is free software; you can redistribute it and/or modify
18+
it under the same terms as Perl itself.
19+
20+
# AUTHOR
21+
22+

cpanfile

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
requires 'perl', '5.014004';
2+
requires 'Class::Accessor::Lite', '0.08';
3+
requires 'Exception::Tiny', '0.2.1';
4+
5+
on 'test' => sub {
6+
requires 'Test::More', '1.302135';
7+
};
8+

lib/Scalish.pm

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
package Scalish;
2+
3+
use Scalish::Exporter; # enables strict, warnigns and utf8
4+
our $VERSION = '0.01';
5+
6+
use Scalish::Option::Some;
7+
use Scalish::Option::None;
8+
use Scalish::Either::Right;
9+
use Scalish::Either::Left;
10+
11+
use Exporter qw( import );
12+
our @EXPORT_OK = qw( option some none right left for_each for_yield );
13+
14+
sub option($) {
15+
defined $_[0] ? Scalish::Option::Some->new( $_[0] ) : Scalish::Option::None->new;
16+
}
17+
18+
sub some($) { Scalish::Option::Some->new( $_[0] ) }
19+
20+
sub none { Scalish::Option::None->new() }
21+
22+
sub right($) { Scalish::Either::Right->new( $_[0] ) }
23+
24+
sub left($) { Scalish::Either::Left->new( $_[0] ) }
25+
26+
sub _rec_for_each {
27+
my ( $iters, $index, $params, $code ) = @_;
28+
if ( $index == @$iters - 1 ) {
29+
$iters->[$index]->foreach(
30+
sub {
31+
my $c = shift;
32+
$code->( @$params, $c );
33+
}
34+
);
35+
}
36+
else {
37+
$iters->[$index]->foreach(
38+
sub {
39+
my $c = shift;
40+
push @$params, $c;
41+
_rec_for_each( $iters, $index + 1, $params, $code );
42+
}
43+
);
44+
}
45+
}
46+
47+
sub for_each {
48+
my ( $iters, $code ) = @_;
49+
_rec_for_each( $iters, 0, [], $code );
50+
}
51+
52+
sub _rec_for_yield {
53+
my ( $iters, $index, $params, $code ) = @_;
54+
if ( $index == @$iters - 1 ) {
55+
$iters->[$index]->map(
56+
sub {
57+
my $c = shift;
58+
$code->( @$params, $c );
59+
}
60+
);
61+
}
62+
else {
63+
$iters->[$index]->flat_map(
64+
sub {
65+
my $c = shift;
66+
push @$params, $c;
67+
_rec_for_yield( $iters, $index + 1, $params, $code );
68+
}
69+
);
70+
}
71+
}
72+
73+
sub for_yield {
74+
my ( $iters, $code ) = @_;
75+
_rec_for_yield( $iters, 0, [], $code );
76+
}
77+
78+
79+
1;
80+
81+
__END__
82+
83+
=encoding utf-8
84+
85+
=head1 NAME
86+
87+
Scalish - It's new $module
88+
89+
=head1 SYNOPSIS
90+
91+
use Scalish;
92+
93+
=head1 DESCRIPTION
94+
95+
Scalish is ...
96+
97+
=head1 LICENSE
98+
99+
Copyright (C) mp0liiu.
100+
101+
This library is free software; you can redistribute it and/or modify
102+
it under the same terms as Perl itself.
103+
104+
=head1 AUTHOR
105+
106+
mp0liiu E<lt>[email protected]E<gt>
107+
108+
=cut
109+

lib/Scalish/Either/Either.pm

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package Scalish::Either::Either;
2+
3+
use Scalish::Exporter;
4+
use parent 'Scalish::Either::Projection';
5+
6+
use Scalish::Option::Some;
7+
use Scalish::Option::None;
8+
use Scalish::Either::LeftProjection;
9+
use Scalish::Either::RightProjection;
10+
11+
# override
12+
sub _content { $_[0]->{content} }
13+
14+
# override
15+
sub _is_available { $_[0]->is_right }
16+
17+
# override
18+
sub filter {
19+
my ( $self, $code ) = @_;
20+
my $result = $self->exists($code);
21+
$result ? Scalish::Option::Some->new($self) : Scalish::Option::None->new;
22+
}
23+
24+
# override
25+
sub flat_map {
26+
my ( $self, $code ) = @_;
27+
$self->map($code)->join_right;
28+
}
29+
30+
sub fold { Carp::croak 'you must define fold method.' }
31+
32+
sub is_left() { Carp::croak 'you must define is_left method.' }
33+
34+
sub is_right() { Carp::croak 'you must define is_right method.' }
35+
36+
sub join_left { Carp::croak 'you must define join_left method.' }
37+
38+
sub join_right { Carp::croak 'you must define join_right method.' }
39+
40+
sub left {
41+
my $self = shift;
42+
Scalish::Either::LeftProjection->new($self);
43+
}
44+
45+
sub merge {
46+
my $self = shift;
47+
$self->{content};
48+
}
49+
50+
sub match;
51+
52+
sub right {
53+
my $self = shift;
54+
Scalish::Either::RightProjection->new($self);
55+
}
56+
57+
sub swap { Carp::croak 'you must define swap method.' }
58+
59+
1;
60+

lib/Scalish/Either/Left.pm

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package Scalish::Either::Left;
2+
3+
use Scalish::Exporter;
4+
use parent 'Scalish::Either::Either';
5+
6+
use Scalish::Either::Right;
7+
8+
sub new {
9+
my ( $class, $content ) = @_;
10+
Carp::croak 'Too few arguments (required: $content)' if @_ < 2;
11+
bless { content => $content }, $class;
12+
}
13+
14+
sub fold {
15+
my ( $self, $left_code, $right_code ) = @_;
16+
Carp::croak 'Too few arguments (required: $left_code, $right_code)'
17+
if @_ < 3;
18+
local $_ = $self->{content};
19+
$left_code->( $self->{content} );
20+
}
21+
22+
sub is_left() { 1 }
23+
24+
sub is_right() { 0 }
25+
26+
sub join_left {
27+
my $self = shift;
28+
$self->{content}->isa('Scalish::Either::Either')
29+
? $self->{content}
30+
: Carp::croak 'cant join_left';
31+
}
32+
33+
sub join_right {
34+
my $self = shift;
35+
$self;
36+
}
37+
38+
sub swap {
39+
my $self = shift;
40+
Either::Right->new( $self->{content} );
41+
}
42+
43+
sub match {
44+
Carp::confess 'Invalid arguments' if @_ < 5;
45+
my ( $self, %args ) = @_;
46+
for (qw/ Right Left /) {
47+
my $code = $args{$_};
48+
Carp::confess " please specify process $_ " if ref $code ne 'CODE';
49+
}
50+
local $_ = $self->{content};
51+
$args{Left}->( $self->{content} );
52+
}
53+
54+
1;

0 commit comments

Comments
 (0)