Skip to content

Commit

Permalink
[#24] Move ISequential and Seqable to List type module
Browse files Browse the repository at this point in the history
  • Loading branch information
jfacorro committed Jan 21, 2016
1 parent 17166e5 commit f8e5d68
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 28 deletions.
8 changes: 0 additions & 8 deletions src/lang/clojerl.Integer.clojerl.Stringable.erl

This file was deleted.

8 changes: 8 additions & 0 deletions src/lang/clojerl.Integer.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-module('clojerl.Integer').

-behaviour('clojerl.Stringable').

-export(['clojerl.Stringable.str'/1]).

'clojerl.Stringable.str'(Int) when is_integer(Int) ->
integer_to_binary(Int).
7 changes: 0 additions & 7 deletions src/lang/clojerl.nil.clojerl.Stringable.erl

This file was deleted.

7 changes: 7 additions & 0 deletions src/lang/clojerl.nil.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-module('clojerl.nil').

-behaviour('clojerl.Stringable').

-export(['clojerl.Stringable.str'/1]).

'clojerl.Stringable.str'(undefined) -> <<"nil">>.
8 changes: 6 additions & 2 deletions src/lang/clojerl.protocol.erl
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ resolve(Protocol, FunctionName, Args = [Head | _]) ->

-spec 'extends?'(atom(), atom()) -> boolean().
'extends?'(Protocol, Type) ->
ImplModule = impl_module(Protocol, Type),
code:is_loaded(ImplModule) =/= false.
(erlang:function_exported(Type, module_info, 1)
andalso
lists:keymember([Protocol], 2, Type:module_info(attributes))
)
orelse
code:is_loaded(impl_module(Protocol, Type)) =/= false.

-spec impl_module(atom(), atom()) -> atom().
impl_module(Protocol, Type) when is_atom(Protocol),
Expand Down
1 change: 0 additions & 1 deletion src/lang/collections/clojerl.List.clojerl.ISequential.erl

This file was deleted.

8 changes: 0 additions & 8 deletions src/lang/collections/clojerl.List.clojerl.Seqable.erl

This file was deleted.

11 changes: 10 additions & 1 deletion src/lang/collections/clojerl.List.erl
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
-module('clojerl.List').

-behaviour('clojerl.Counted').
-behaviour('clojerl.Stringable').
-behaviour('clojerl.Seqable').
-behaviour('clojerl.ISeq').
-behaviour('clojerl.ISequential').

-export([ new/1
, to_list/1
]).

-export(['clojerl.Counted.count'/1]).

-export(['clojerl.Stringable.str'/1]).
-export(['clojerl.Seqable.seq'/1]).

-type type() :: {?MODULE, list()}.

Expand All @@ -25,3 +31,6 @@ to_list({_, List, _}) -> List.
ItemsStrs = lists:map(fun clj_core:str/1, Items),
Strs = clj_utils:binary_join(ItemsStrs, <<", ">>),
<<"(", Strs/binary, ")">>.

'clojerl.Seqable.seq'({_, [], _}) -> undefined;
'clojerl.Seqable.seq'({_, Seq, _}) -> Seq.
11 changes: 10 additions & 1 deletion test/clojerl_List_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
-export([ new/1
, count/1
, str/1
, is_sequential/1
]).

-spec all() -> [atom()].
Expand All @@ -23,7 +24,10 @@ all() ->
-spec new(config()) -> result().
new(_Config) ->
List = clj_core:list([1, 2, 3]),
[1, 2, 3] = clj_core:seq(List).
[1, 2, 3] = clj_core:seq(List),

List2 = clj_core:list([]),
undefined = clj_core:seq(List2).

-spec count(config()) -> result().
count(_Config) ->
Expand All @@ -40,3 +44,8 @@ str(_Config) ->

List2 = clj_core:list([]),
<<"()">> = clj_core:str(List2).

-spec is_sequential(config()) -> result().
is_sequential(_Config) ->
List = clj_core:list([1, 2, 3]),
true = clj_core:'sequential?'(List).

0 comments on commit f8e5d68

Please sign in to comment.